0

I was coding a small game, when i got an error from intelisense. I tried again with a simple pet class, but intellisense didn't think it was correct. here is the code and the errors:

#include <iostream>
class Pet{
public:
    int m_hunger;
    void Greet();
};
void Pet::Greet(){
    std::cout << "My hunger is " << m_hunger;
}
int main(){
    Pet dog();
    dog.m_hunger = 9;//Expression must have class type
    dog.Greet();//Expression must have class type
    return 0;
}
Ken White
  • 123,280
  • 14
  • 225
  • 444
aedo
  • 1
  • 1
  • I recommend printing "\n" at the end of your output or using `std::endl`. Both will flush the data in buffers to the standard output. – Thomas Matthews Jan 28 '16 at 19:28

1 Answers1

5

Pet dog(); does not create a Pet. It creates a function named dog that returns a Pet and takes no parameters.

You can change it to Pet dog; which will create a Pet named dog.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402