Given a template class as such:
template <typename TYPE>
class SomeClass {
public:
typedef boost::intrusive_ptr<SomeClass<TYPE> > Client_t;
inline Client_t GetClient() { return Client_t(this); }
};
SomeClass is intended only to be used via pointer references returned by SomeClass::GetClient(). Which makes it natural to write a wrapper function around creation like this:
template <typename TYPE>
SomeClass<TYPE>::Client_t New_SomeClass() {
return (new SomeClass<TYPE>)->GetClient();
}
Compiling the above code under GCC 4.4:
SomeClass<int>::Client_t some_class = New_SomeClass();
Gives the error "‘New_SomeClass’ was not declared in this scope"
Now I'm no template wizard, so there could be details here I'm not aware of, but I'm guessing I can't use a construct of this sort at all due to the fact that C++ doesn't allow overloading on return type.
I guess a...shiver... macro would solve it:
#define NEW_SOMECLASS(TYPE) ((new SomeClass<TYPE>)->GetClient())
auto some_class = NEW_SOMECLASS(int);
But there has to be a sensible way to expose object creation of a template class without resorting to macros or other cumbersome constructs?