For the class dataCard
here's an implementation of its constructor (here name
is a public member of type const char*
:
dataCard::dataCard(const char* fname) {
...
name = fname;
...
}
And copy constructor:
dataCard::datCard(const dataCard& rhs) {
...
name = rhs.name;
...
}
When later in main
I initialize an object of type dataCard
as follows
dataCard card("myCard");
and try to print its name
cout << card.name;
I obviously get
myCard
However when I put this object in a vector
vector<dataCard> cards;
cards.push_back(myCard);
and try to print the name of the card this way
cout << cards[0].name;
the name is not represented correctly. I get some strange sequence of unknown symbols instead of the expected myName
.
I suspect there's a problem with the copy constructor and the type const char*
, since I have another member of type char
in my class, which is represented properly when calling it after putting the element into the vector. Where does the problem lie?