Hello I am working on a C++ program and I am just starting out by creating some sample objects out of the class that I created. I am creating the object but for some reason the dot operator is not working with the object
This is the object call
Card testcard(Suit hearts, Value six);
This is the constructor
Card::Card(Suit suit, Value facevalue)
{
Card::suit=suit;
Card::faceValue=facevalue;
};
However the dot operator is not working, as if the object is not really there
I am controlling most of the program in seperate parts so there are many instances of header files which is where the card class is located, I am not sure if that is part of the problem
Assuming the class looks something like:
class Card {
public:
Card (Suit argSuit, Value argFaceValue);
private:
Suit m_Suit;
Value m_FaceValue;
};
The constructor would look like this. Since the members of the class are available to the objects created from the class you do not need to do anything special to access them. The members of the class are within scope and are visible. You just need to make sure that the argument list of the function uses different symbols or names than the class/object members.
Card::Card(Suit argSuit, Value argFaceValue)
{
m_Suit = argSuit;
m_FaceValue = argFaceValue;
}