I'm getting a strange error when i tried do display some information. Here it's a portion of my class code:
class Vertex
{
public:
Vertex(int name)
{
name = name;
pred = NULL;
color = 'w';
desc = 1000000;
}
int getName() {return name;}
char getColor() {return color;}
Vertex* getPred() {return pred;}
int getDesc() {return desc;}
void setColor(char c) {color = c;}
void setPred(Vertex *p) {pred = p;}
void setDesc(int d) {desc = d;}
private:
int name;
char color;
Vertex* pred;
int desc;
};
I believe this is okay... but when i do this in my main function (which i believe it's also ok...):
for(int z = 1; z <= nsomething; z++){
Vertex v(z);
cout << "from z=" << z << " is vertex name: " << v.getName() << endl;
cout << "from z=" << z << " is vertex color: " << v.getColor() << endl;
Vertex *vp = &v;
cout << "from z=" << z << " is vertex name: " << vp->getName() << endl;
cout << "from z=" << z << " is vertex color: " << vp->getColor() << endl;
}
I get this:
from z=1 is vertex name: 1854338496
from z=1 is vertex color: w
from z=1 is vertex name: 1854338496
from z=1 is vertex color: w
from z=2 is vertex name: 1854338496
from z=2 is vertex color: w
from z=2 is vertex name: 1854338496
from z=2 is vertex color: w
Can someone help me, telling why is this happening only with the getName()?
Thanks in advance!