codeBuilder
asked on
Why this endline gives Segmentation Fault (core dumped)
ostream& operator<<(ostream& stream, Network& network)
{
int a;
int s = network.nodes.size();
for (a=0;a<s;a++)
{
stream << *(network.nodes[a]);
}
}
ostream& operator<< (ostream& stream, const Node& node)
{
stream << node.label ;
}
int main()
{
Node * n = new Node("W");
cout << *n ; // IT WORKS
cout << *n <<endl; // IT WORKS
Network * x = new Network();
x->addNode("A");
cout << *x // IT WORKS
cout << *x << endl // THE endl causes segmentation fault (core dumped). WHY??What should i do?
}
Any help is appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Point shot
ASKER
In addition , i am surprised now how it can compile correctly , but maybe it won't give any warning because i don't state any extra option while compiling . I compile as the following: g++ -o example example.cpp