Original Post
How does one know when to use a default constructor or not???
quote:
Original post by xg0blin
If when you make an instance of your class you don''t put any values in for your constructor, if you have default values, they will be put in instead, thus you''re default constructor.
class CPeg{
public:
CPeg(stack<int> pStack,const string& itsName):
pegStack(pStack),name(itsName)
{}
~CPeg();
int addRing(int rSize){
if(rSize < pegStack.top()){
pegStack.push(rSize);
return OK;
}else
return FAILED;
}
void removeRing(){ pegStack.pop(); }
private:
stack<int> pegStack;
string name;
};
quote:
Original post by pdstatha
So if I were to create an instance of a peg in my main cpp file, would that constructor be correct, or do I not need the "stack<int> pStack" bit?
CPeg myPeg( new stack<int>, "myPeg" );
CPeg myOtherPeg;
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more