Y
Yin99
I'm expecting to see itsAge = 0 in the output of the following code.
However, in the main() function, itsAge = 1 . Can someone explain??
thanks,
Yin99
===== begin code ======
#include <iostream>
using namespace std;
class Cat
{
public:
Cat(){
itsAge = 0;
cout << "constuctor age is: " << itsAge; //zero here!
}
void setAge(int age){
itsAge = age;
}
int getAge(){
return itsAge;
}
private:
int itsAge;
};
int main ()
{
Cat *c = new Cat();
//c->getAge returns 1 here, Why and Where does 1 come from?
cout << "Cat's Age is: " << c->getAge;
return 0;
}
However, in the main() function, itsAge = 1 . Can someone explain??
thanks,
Yin99
===== begin code ======
#include <iostream>
using namespace std;
class Cat
{
public:
Cat(){
itsAge = 0;
cout << "constuctor age is: " << itsAge; //zero here!
}
void setAge(int age){
itsAge = age;
}
int getAge(){
return itsAge;
}
private:
int itsAge;
};
int main ()
{
Cat *c = new Cat();
//c->getAge returns 1 here, Why and Where does 1 come from?
cout << "Cat's Age is: " << c->getAge;
return 0;
}