Mapping integers to types using C++ template fails in a specific case -


I am trying to compile the following template based code in VC ++ 2005.

  #include & lt; Iostream & gt; using namespace std; / * * T is a template that maps to an integer for a specific type. * Mapping is done through partial template expertise * The following t & lt; 1 & gt; Has been mapped to four, T & LT; 2 & gt; Has been mapped for long * and t & lt; 3 & gt; Partial Template Specialists * / Templates & lt; Int x & gt; Has been mapped to float using. Structure t {public:}; The template's & lt; & Gt; Structure t & lt; 1 & gt; {PUBLIC: TYPE TEXT FOUR EXTEP; }; The template's & lt; & Gt; Structure t & lt; 2 & gt; {Public: Long exhaust type; }; The template's & lt; & Gt; Structure t & lt; 3 & gt; {Public: Typefaf float exetype; }; // We will not accept any special T & lt; N & gt; Typically xType can be accessed easily. Typedef T & lt; 3 & gt; :: xType x3Type; / *! * In the following we do not have the t & lt; N & gt; Trying to use. Another * template inside class T2 & lt; R & gt; * / Template & lt; Int r & gt; Structure T2 {// We T & lt; R> Any other type of T3 Typingfed T & lt; R> T3; // typedef T3 :: xType xType failed in the following line; }; Int main () {T & lt; 1 & gt; :: xType a1; Cout & lt; & Lt; Typed (A1) .name () & lt; & Lt; Endl; T & lt; 2>: xType a2; Cout & lt; & Lt; Typed (A2) .name () & lt; & Lt; Endl; T & LT; 3>: xType a3; Cout & lt; & Lt; Typed (A3) .name () & lt; & Lt; Endl; Return 0; }  

There is a special line in the code that does not compile:

  typedef T3 :: xType xType;  

If I extract this line, then the compile gets cured and its result is:

>

If I retain this line, compilation errors are celebrated.

  main.cpp (53): Warning C4346: 't & lt; X & gt; :: xType ': Depending on the name' typename is not a type prefix 'to indicate one type main.cpp (54): The class template's instant' T2 and lieutenant; R & gt; Compile is being main.cpp (53): error C2146: syntax error: missing ';' 'XType' main.cpp (53) before identifier: Error C4430: Missing type specifier - int assumed. Note: C ++ does not support default-int  

I'm not able to ensure that T: extty can be considered as a type of T2 template inside is. Any help is highly appreciated.

Since T3 is dependent in your template class, the template parameter, the compiler ensures it You can not know how to refer to T3 :: xType (which may be dependent on the real type of r each urgency T2 ).

To tell the compiler that T3 :: xType will be a type, you typename keyword:

  Type typed T3 :: xType xType;  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -