G
Guest
Test case:
#include <boost/shared_ptr.hpp>
using namespace boost;
template <typename typ1> class cData {
public:
template <typename T> T As() { } // As
};
template <typename D, typename T>
class cTaggedData : public cData<D> {
public:
};
template <typename D, typename T>
class cAttr : public cTaggedData<D,T> {
public:
};
template <typename D, typename T>
class cNode : public cTaggedData<D,T> {
public:
shared_ptr< cAttr<D,T> > RetAttr() { }
template <typename X> X MyAs(T t, X& x) {
#line 100
shared_ptr< cAttr<int,int> > attr1; attr1->As<int>(); // works
#line 200
shared_ptr< cAttr<D,T> > attr2; attr2->As<int>(); // FAILS
#line 300
shared_ptr< cAttr<int,int> > attr3; attr3->As<X>(); // works
#line 400
shared_ptr< cAttr<D,T> > attr4; attr4->As<X>(); // my goal, FAILS
} // As
};
/*
gives:
x.cpp: In member function 'X cNode<D, T>::MyAs(T, X&)':
x.cpp:200: error: expected primary-expression before 'int'
x.cpp:200: error: expected `;' before 'int'
x.cpp:400: error: expected primary-expression before '>' token
x.cpp:400: error: expected primary-expression before ')' token
*/
int main() { }
How to fix thoes two errors? Especially the 400 one?
#include <boost/shared_ptr.hpp>
using namespace boost;
template <typename typ1> class cData {
public:
template <typename T> T As() { } // As
};
template <typename D, typename T>
class cTaggedData : public cData<D> {
public:
};
template <typename D, typename T>
class cAttr : public cTaggedData<D,T> {
public:
};
template <typename D, typename T>
class cNode : public cTaggedData<D,T> {
public:
shared_ptr< cAttr<D,T> > RetAttr() { }
template <typename X> X MyAs(T t, X& x) {
#line 100
shared_ptr< cAttr<int,int> > attr1; attr1->As<int>(); // works
#line 200
shared_ptr< cAttr<D,T> > attr2; attr2->As<int>(); // FAILS
#line 300
shared_ptr< cAttr<int,int> > attr3; attr3->As<X>(); // works
#line 400
shared_ptr< cAttr<D,T> > attr4; attr4->As<X>(); // my goal, FAILS
} // As
};
/*
gives:
x.cpp: In member function 'X cNode<D, T>::MyAs(T, X&)':
x.cpp:200: error: expected primary-expression before 'int'
x.cpp:200: error: expected `;' before 'int'
x.cpp:400: error: expected primary-expression before '>' token
x.cpp:400: error: expected primary-expression before ')' token
*/
int main() { }
How to fix thoes two errors? Especially the 400 one?