2012-01-25 8 views
5

C'è un Tout struttura contenente struttura interna TIn:C++ passare struttura interna come parametro di

template <typename T> 
struct TOut 
{ 
    struct TIn 
    { 
      bool b; 
    }; 

    TIn in; 
T t; 
}; 

come passare correttamente TIn come un parametro formale di qualche metodo?

class Test 
{ 
public: 
    template <typename T> 
    static void test (const TOut<T>::TIn &i) {} //Error 
}; 


int main() 
{ 
TOut <double> o; 
Test::test(o.in); 
} 

Il programma viene compilato con il seguente errore:

Error 4 error C2998: 'int test' : cannot be a template definition 
+0

http://stackoverflow.com/questions/7178948/problem-with-functions-accepting-inner-classes-of-template-classes – Lol4t0

+0

@TJD 'Tin' sarebbe un tipo noto (" concreto ") se dove dichiarato accanto a 'Tout', o all'interno di una classe non template. Nel momento in cui l'OP sta ricevendo un errore, 'Tin' non è ancora noto, perché' TOut ' non è stato ancora istanziato. A proposito, il termine "concreto" viene normalmente utilizzato nel contesto dell'ereditarietà (opposto di "astratto"). –

risposta

2

Perché non è possibile utilizzare la più semplice

template <typename T> 
static void test (const T& i) 

?