[ create a new paste ] login | about

Link: http://codepad.org/mg9U6rsu    [ raw code | output | fork ]

C++, pasted on Sep 8:
class Hoge
{
  public:
    Hoge():x(0), p(&x){}
    virtual ~Hoge(){}
    void Foo(const int&) const;

  private:
    int x;
    int* p;
};

void Hoge::Foo(const int& value) const
{
  //x = 1;     //Compile Error!
  *p = value;  //OK
  cout << x << endl;  //Foo is const...variable x
}

int main()
{
  Hoge hoge;
  hoge.Foo(10);
}


Output:
1
10


Create a new paste based on this one


Comments: