P
Patrick Kowalzick
Dear all,
IMO the following program is legal and should compile.
//***** code start *********
// Definition of class A
template <typename T> struct A
{
typedef T value_type;
};
// Definition of class B
template <typename> struct B {};
// Function foo
// returntype important !
template <typename T>
B<typename T::value_type> foo()
{
return B<typename T::value_type>();
};
int main()
{
typedef B< int >( * ptr )(); // Function pointer
ptr foo_ptr = foo< A<int> >; // Initialization of function pointer
return 0;
}
//***** code end *********
It builds fine with g++ and MSVC7.1, but the latter one fails linking:
unresolved external symbol "struct B<int> __cdecl foo<struct A<int> >(void)"
(??$foo@U?$A@H@@@@YA?AU?$B@H@@XZ) referenced in function _main
what I do not really understand. It is getting a lit more weird now. If I
change
ptr foo_ptr = foo< A<int> >;
to
ptr foo_ptr ;
foo_ptr = foo< A<int> >;
it compiles and links fine as well with MSVC 7.1.
Before I blame anyone, I want to ask if I overlooked something? IMO the code
is fine.
Regards,
Patrick
IMO the following program is legal and should compile.
//***** code start *********
// Definition of class A
template <typename T> struct A
{
typedef T value_type;
};
// Definition of class B
template <typename> struct B {};
// Function foo
// returntype important !
template <typename T>
B<typename T::value_type> foo()
{
return B<typename T::value_type>();
};
int main()
{
typedef B< int >( * ptr )(); // Function pointer
ptr foo_ptr = foo< A<int> >; // Initialization of function pointer
return 0;
}
//***** code end *********
It builds fine with g++ and MSVC7.1, but the latter one fails linking:
unresolved external symbol "struct B<int> __cdecl foo<struct A<int> >(void)"
(??$foo@U?$A@H@@@@YA?AU?$B@H@@XZ) referenced in function _main
what I do not really understand. It is getting a lit more weird now. If I
change
ptr foo_ptr = foo< A<int> >;
to
ptr foo_ptr ;
foo_ptr = foo< A<int> >;
it compiles and links fine as well with MSVC 7.1.
Before I blame anyone, I want to ask if I overlooked something? IMO the code
is fine.
Regards,
Patrick