Refrences and a dog named skinbag.
Hey...I need help. :mad:
I was atempting to pass a reference through a class method and then use the method to access the private integer 'age' with the reference. This isn't for a program but I need to understand this. Any help would be apreciated. :confused:
My compiler is :MSVC++ 6...the error is located at the bottom. What I need to know is how to access the private int age using a reference...thanks. :confused:
#include <iostream.h>
class dog //Telling compiler what a dog is..
{
public:
int getAge;
void setAge(int &rAge) //passing a reference
{
rAge=age; //declaring the reference to age.
}
private:
int age;
};
int main()
{
dog SkinBag; //Making my dog...
SkinBag.setAge(5); //error line ... Setting skinbags age
return 0;
}
error:
D:\Vc98\playingaround.cpp(19) : error C2664: 'setAge' : cannot convert parameter 1 from 'const int' to 'int &'
A reference that is not to 'const' cannot be bound to a non-lvalue