0

In my C++ class I need to assign a method with pointer and/or reference. So I do this tricky thing :

(Assuming aclass is a class variable AnotherClass *)

void MyClass::setElem(AnotherClass *pVal)
{
  aclass = pVal;
}

void MyClass::setElem(AnotherClass &refVal)
{
  aClass = &article;
}

But in my opinion, sounds not so "graceful"...

Better way to achieve this ?

4

1 回答 1

7
void MyClass::setElem(AnotherClass *pVal)
{
  aclass = pVal;
}

void MyClass::setElem(AnotherClass &refVal)
{
  setElem(&refVal);
}

Is this graceful enough? As Mr. Pitt once said in Seinfeld "Well, you don't want too much grace or you won't be able to stand".

于 2013-07-19T09:31:11.290 回答