我认为这是一个愚蠢的问题,并且有很多充分的理由不应该考虑这样的事情,但是现在让我们忽略它......
我知道一个人不能超载" dot" C ++中的运算符。 C ++在反射功能方面也缺乏,因此提供在编译时尝试伪造它的方法也很棘手......
无论如何,现在让我以一个例子的形式提出这个问题:
class Foo
{
...
public:
int bar();
...
};
template <class T>
class Bar
{
T* m_ptr; // perhaps use an unique_ptr for safety.
...
public:
Bar(T* ptr) : m_ptr(ptr) { } // create a local copy instead
int qux();
...
}
int main()
{
Foo quux;
Bar corge(&quux);
corge.bar(); // I want to do this instead of corge->bar();
corge.qux(); // without losing this functionality!
// Is there a way to do such a thing?
// my expectations: \(^.^)/
// what is probably the sad truth: /(;.;)\
// Also, I realize there should be no good reason to do this...
// Just pretend I have a really really REALLY good reason to want to do this :P
// Thanks!! :D
}