What is the correct way to refer to this function using c++?
I'm writing a program that's meant to eventually work as a yatzy game for a course I'm doing in c++ programming. I have been given a cla开发者_Go百科ss called Die from the course that I'm meant to use and I'm not allowed to change it. When trying to refer to a specific function within the class given to me Xcode issues a warning saying "Cannot refer to type member 'Die' in 'Die' with '.'. This is the code I'm having problems with:
for (i = 100; i > 0; i--)
{
Die D;
D.Die(); //This is the line not working
D.rollDie();
dice_value = D.getDieValue();
Is there any other way to refer to a function? Does anybody know what could be causing this problem? I really appreciate any help given!
You don't need that line of code at all. D's default constructor is called automatically by the compiler for any object instantiated on the stack (i.e., local variables).
If you're trying to call Die
's constructor, don't: you've already done that.
Die D;
calls Die
's default constructor already. D
is initialized after that point.
Die D;
D.Die(); //This is the line not working
Thats not good. Die D allready calls a constructor !
精彩评论