3
我想寫一個簡單的包裝另一類。一個小例子:如何在C++中重載' - >'運算符?
class MyClass {
...
int someMember();
...
};
class MyClassRefernence{
...
MyClass* ptr;
MyClass& operator *();
...
};
如果我現在有一些類似於下面的代碼:
MyClassReference ref;
... // Init the ref and the pointer ptr.
int a = (*ref).someMember(); // this works but is nasty
int b = ref->someMember(); // Compile error
所以我的問題是:有沒有辦法使用的,而不是(*...).
建設更幾乎->
操作方式?
好的,謝謝。我認爲'operator *()'就足夠了。 – 2012-03-09 12:44:06