I have a snippet of code that similar to the way of implementing smart pointer in C++.
template <class T>
class WrapObject
{
public:
WrapObject(T* data)
{
_data = data;
}
T* operator->()
{
return _data;
}
private:
T* _data;
};
class Hello
{
public:
void sayHello()
{
std::cout << "hello world" << std::endl;
}
};
int main() {
Hello h;
WrapObject<Hello> wh(&h);
wh->sayHello();
return 0;
}
in main function, we can access to all methods of Hello object directly from WrapObject using operator '->'.
is there any way to do thing like this in C# or Java??