template < class T, class U, class V, class W > class MyClass
{
public:
static void someFunc();
};
typedef MyClass< int, double, int, char > UseThis;
// Make an instance.
UseThis AnInstance;
template < class T, class U, class V, class W > class MyClass
{
public:
static void someFunc();
};
typedef MyClass< int, double, int, char > UseThis;
// Make an instance.
UseThis AnInstance;
Quote:Original post by Red Ant
Hello,
Assuming I have a template ...
*** Source Snippet Removed ***
I can do this to cut down on the typing I need to do to access the class ...
*** Source Snippet Removed ***
But can I do something like that for the someFunc() method, too? If so, how?
typedef MyClass< int, double, int, char > UseThis;UseThis::someFunc();
template < class T, class U, class V, class W > class MyClass{};template < class T, class U, class V, class W >MyClass< T, U, V, W >* makeInstance(){ return new MyClass< T, U, V, W >;}
Quote:Original post by Red Ant
Yeah sorry, I just realized that I haven't correctly described my problem.
*** Source Snippet Removed ***
That's what I really want. Is it possible to make the makeInstance() function more easily accessible via some typedef magic?
template < class T, class U, class V, class W > class MyClass{};template < class T, class U, class V, class W >MyClass< T, U, V, W >* makeInstance(){ return new MyClass< T, U, V, W >;}MyClass<int,double,int,char>* (*const makeInstance_simple)() = &makeInstance< int, double, int, char>;
#define makeInstance_simple makeInstance<int, double, int, char>
inline MyClass< int, double, int, char >* makeInstance_simple(){ return makeInstance<int, double, int, char>();}
template<typename TL> class MyClass{ typedef typename Loki::TL::TypeAt<TL,0>::Result T; typedef typename Loki::TL::TypeAt<TL,1>::Result U; typedef typename Loki::TL::TypeAt<TL,2>::Result V; typedef typename Loki::TL::TypeAt<TL,3>::Result W; // ...};// the types you wanttypedef LOKI_TYPELIST_4(int, double, int, char) types_t;// instanciateMyClass<types_t> fnar;
namespace std { template <typename T1, typename T2> struct pair { T1 first; T2 second; pair(const T1& x, const T2& y) : first(x), second(y) {} // possibly some other functions I forgot? }; template <typename T1, typename T2> pair<T1, T2> make_pair(const T1& x, const T2& y) { return pair<T1, T2>(x, y); } // Now calling code can do 'std::make_pair(foo, bar)' and not have to specify // the type names.}
template < class T, class U, class V, class W > class MyClass{};template < class T, class U, class V, class W >MyClass< T, U, V, W >* makeInstance(){ return new MyClass< T, U, V, W >;}MyClass< a, b, c, d >* my_makeInstance() { return makeInstance<a, b, c, d>();};
Quote:Original post by Red Ant
Yeah sorry, I just realized that I haven't correctly described my problem.
*** Source Snippet Removed ***
That's what I really want. Is it possible to make the makeInstance() function more easily accessible via some typedef magic?
typedef MyClass< int, double, int, char > UseThis; // Make an instance. UseThis AnInstance; template < class T, class U, class V, class W > MyClass< T, U, V, W >* makeInstance() { return new MyClass< T, U, V, W >; } inline UseThis * makeUseThisInstance() { return makeInstance< int, double, int, char >(); } UseThis * NewInstance = makeUseThisInstance();