I just started an advanced C++ course and my instructor sent around a file with this piece of code:
class smallobj // specify a class
{
public:
smallobj() : iData(0){} // Constructor
smallobj(int iInValue) : iData(iInValue) {} // Overloaded Constructor
~smallobj() {} // Destructor
void setdata(int d) // member function (sets iData)
{ iData = d; } // define the function here because
// it's so short
void showdata() // member function to display iData
{cout << "\nThe Value of data is: " << iData; }
private:
int iData;
};
I'm confused by the prototypes of the constructors. I've seen some of the other members here write similar prototypes/definitions in their posts. I've also seen VC++ add this information to the constructors in its auto-generated class definitions.
I've done some searches for " : in C++ function definition" and similar but didn't find anything that seemed relevant (actually got several threads in the PHP forum as well).
I've also looked through a couple tutorial documents and my textbook, no luck. The closest I have been able to find is in relation to class inheritance. I think this may be something like that, but that doesn't make sense to me. It can't be part of the ternary operator, there isn't any '?'. The MS-VC++ help has a worthless blurb that calls it some sort of segment operator which just confused me more. It seems more that it's some sort of auto-declaration/initialization shortcut.
What exactly does this type of notation do?
Thanks.