This class is Foo
template <typename T>
class Foo
{
public:
...other methods..
void bar()
{
...
m_impl.doSomething();
...
}
void fun()
{
...
m_impl.doSomethingElse();
...
}
void fubar()
{
...
}
private:
T m_impl;
};
I wanted to serve situations where T is boost :: shared_ptr. In this case, the only change to the Foo class is that it should call
m_impl->doSomething();
instead
m_impl.doSomething();
I ended up defining FooPtr in the same header
template <typename T>
class FooPtr
{
public:
...other methods..
void bar()
{
...
m_pImpl->doSomething();
...
}
void fun()
{
...
m_pImpl->doSomethingElse();
...
}
void fubar()
{
...
}
private:
boost::shared_ptr<T> m_pImpl;
};
Now that the approach works for all the classes that I want to use with Foo, the problem is that I have a lot of duplicate code, and all the changes I make Foo, I also need to make FooPtr.
How can I reorganize the code? For instance. Is there a way that I can determine at compile time if T is of type boost :: shared_ptr and then specializes only in bar and fun methods to call the → operator?
:
! , , .
2:
@Matthieu: ,
class FooImpl
{
public:
void doIt()
{
cout << "A" << std::endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Foo<FooImpl> foo;
foo.doSomething();
return 0;
}