What is type T?

In the code below:

template<typename T>
struct X {};

int main()
{
  X<int()> x; // what is the type of T ?
}

What is type T? I saw something similar in the sources boost.

+5
source share
3 answers

Consider the function int func(). It has a function type int(void). It can be implicitly converted to a pointer type, as specified in the C ++ standard in 4.3 / 1, but in this case there is no need for such a conversion, therefore it Thas a function type int(void), not a pointer to it.

+12
source

Here is what I did. Although the code output below is implementation specific, it provides a good hint many times over the type T we are dealing with.

template<typename T> 
struct X {
   X(){
      cout << typeid(T).name();
   }
}; 

int main() 
{ 
  X<int()> x; // what is the type of T ? 
  cout << typeid(int()).name() << endl;
} 

Output to VC ++ -

int __cdecl (void)

int __cdecl (void)

+2
source

T - , int, :

template<typename T>
struct X {};

int foo()
{
    return 42;
}
int main()
{
  X<int()> x; // what is the type of T ?
    typedef int(foo_ptr)();
    X<foo_ptr> x2;
    return 0;
}

T x x2 .

0

All Articles