confuse by typeid()

X

XHengDF

#include "iostream"
struct C {
template <typename T> void foo(){}
};

int main()
{
std::cout << typeid( (&C::foo<int>) ).name() << std::endl;
}
output: int
anybody could tell me WHY?

thanks!
 
A

Alan Johnson

#include "iostream"
struct C {
template <typename T> void foo(){}
};

int main()
{
std::cout << typeid( (&C::foo<int>) ).name() << std::endl;
}
output: int
anybody could tell me WHY?

thanks!

Doesn't compile at all for me. With gcc 3.4.4:

$ g++ -Wall -ansi -pedantic test.cpp
test.cpp: In function `int main()':
test.cpp:8: error: address of overloaded function with no contextual
type information
 
I

Ian Collins

#include "iostream"
struct C {
template <typename T> void foo(){}
};

int main()
{
std::cout << typeid( (&C::foo<int>) ).name() << std::endl;
}
output: int
anybody could tell me WHY?
Which compiler? Looks broken to me.
 
I

Ian Collins

i use vs2005!
but now i don't think it fit the c++ standard! right?
Well I get 'void(*)()' from Sun CC, where I'd expect void(C::*)(). Must
be confused by the redundant template <typename T>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top