How to get store a value returned by a const member function?

rag84dec's Avatar, Join Date: Jul 2007
Go4Expert Member
Hi ,
I have a const member function which returns a protected member of a class.Like this
Code:
class A
{
protected:
int Number;
public:
 int   Get_Number   (void) const   { return(Number);  }
};

I want to use the value returned by the Get_Number function.
How can i do

int temp=Data.Get_Number(); is giving me an execption(Data is of type "A&")


Can anyone help me??...
0
rvirma's Avatar
Newbie Member
Data is object of class A . Declare it

const A Data;
0
asadullah.ansari's Avatar, Join Date: Jan 2008
TechCake
Code: cpp
class MyTest
{
protected:
  int n;
public:
  int GetVal()const
  {
    return n;
  }
  void SetVal(int num)
  {
    n=num;
  }
};

int main()
{
 int temp;
 MyTest obj;
 obj.SetVal(10);
 temp=obj.GetVal();
cout<<temp;
 return 0;
}

This code has no problems. What's your problem??? Let me know exactly what u wanna?