1
The execution of my code returns this error written in the title. I don’t know what to do about it because, if you see the code, of course the type of the parameter is BlockGraph
and not int
. When I put an integer value in place of block, no error is returned.
#include <iostream>
#include <iomanip>
#include <vector>
#define INF 0x3f3f3f3f
#define BOUND 99.99
typedef int Vertex;
typedef double Weight;
using namespace std;
class BlockGraph
{
private:
int qtyVertices;
vector< vector<Weight> > adjMatrix;
public:
BlockGraph( int );
void addEdge( Vertex, Vertex, Weight );
void displayGraph();
};
BlockGraph::BlockGraph( int qtyVertices )
{
this->qtyVertices = qtyVertices;
adjMatrix.resize( qtyVertices+1 );
for( int i = 1; i <= qtyVertices; i++ )
adjMatrix[i].resize( qtyVertices+1, BOUND );
}
void BlockGraph::addEdge( Vertex v, Vertex u, Weight w )
{
adjMatrix[u][v] = w;
adjMatrix[v][u] = w;
}
void BlockGraph::displayGraph()
{
cout << endl << " ";
for( int i = 1; i <= qtyVertices; i++ )
cout << setw(7) << "u";
cout << endl << " ";
for( int i = 1; i <= qtyVertices; i++ )
cout << setw(7) << i;
cout << endl << endl;
for( int i = 1; i <= qtyVertices; i++ ){
cout << setw(3) << "v" << setw(3) << i << "|";
for( int j = 1; j <= qtyVertices; j++ ){
cout << fixed << setprecision(2);
if( adjMatrix[i][j] == BOUND )
cout << setw(7) << "INF";
else
cout << setw(7) << adjMatrix[i][j];
}
cout << endl;
}
}
//it's a inherit!
class BrainGraph: public BlockGraph
{
private:
int qtyVertices;
vector< pair<BlockGraph, int> > blocks;
vector< vector<Weight> > adjMatrix;
public:
BrainGraph( int );
void addBlock( BlockGraph, int );
BlockGraph* getBlock( Vertex );
};
BrainGraph::BrainGraph( int qtyVertices ):BlockGraph( qtyVertices )
{
BlockGraph nil(0);
blocks.push_back( make_pair( nil, 0 ) );;
}
// ------------ MÉTODO DA CLASSE CHAMADO --------------
void BrainGraph::addBlock( BlockGraph block, int sickcells )
{
blocks.push_back( make_pair( block, sickcells ) );
}
// ------------ MÉTODO DA CLASSE CHAMADO --------------
BlockGraph* BrainGraph::getBlock( Vertex x )
{
return &blocks[x].first;
}
int main()
{
BrainGraph* brain;
BlockGraph* block;
int orderBrain, qtyEdgesBrain;
int orderBlock, qtyEdgesBlock;
int sickcells, h;
Vertex x, y, start, finish;
Weight w;
cin >> orderBrain >> qtyEdgesBrain;
brain = new BrainGraph( orderBrain );
for( int i = 1; i <= qtyEdgesBrain; i++ ){
cin >> x >> y >> w;
brain->addEdge( x, y, w );
}
cin >> start >> finish;
for( int i = 1; i <= orderBrain; i++ ){
cin >> orderBlock >> qtyEdgesBlock >> sickcells;
block = new BlockGraph( orderBlock );
if( sickcells > 0 )
for( int l = 0; l < sickcells; l++ )
cin >> h;
for( int j = 1; j <= qtyEdgesBlock; j++ ){
cin >> x >> y >> w;
block->addEdge( x, y, w );
}
// ------------ ERRO NESSA LINHA --------------
brain->addBlock( block, sickcells );
// ------------ ERRO NESSA LINHA --------------
delete[] block;
}
brain->displayGraph();
for( int v = 1; v <= orderBrain; v++ ){
cout << endl << endl;
block = brain->getBlock( v );
block->displayGraph();
}
return 0;
}
The IDE also returns note: initializing argument 1 of 'BlockGraph::BlockGraph(int)'|