This code was provided to me by my teacher, as an example of functions in a C++ class. It seems strange to me. I've always been used to ending a function with a }
. I think that only the class definition ends with };
. Here the function definitions end with };
. How is a function in a class, besides being public or private, different from a stand alone function? Is this just a quirk or peculiarity of C++?
class GenericItem {
public:
void SetName(string newName) {
itemName = newName;
};
void SetQuantity(int newQty) {
itemQuantity = newQty;
};
void PrintItem() {
cout << itemName << " " << itemQuantity << endl;
};
private:
string itemName;
int itemQuantity;
};
};
array initialization ends with};
eg:int a[] = {0};
– Raindrop7 Dec 2 '16 at 23:39int a{5};
– Lightness Races in Orbit Dec 2 '16 at 23:41;
does not end initilization, it ends declaration. – AnT Dec 3 '16 at 0:20