Click here to Skip to main content
15,901,035 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralChart in VC++ MFC Pin
Aky6-Jun-01 19:59
Aky6-Jun-01 19:59 
GeneralRe: Chart in VC++ MFC Pin
Christian Graus7-Jun-01 13:29
protectorChristian Graus7-Jun-01 13:29 
GeneralWhat's wrong with my code? (class template) Pin
Li Lirong6-Jun-01 19:25
Li Lirong6-Jun-01 19:25 
GeneralRe: What's wrong with my code? (class template) Pin
Vivek Rajan6-Jun-01 20:00
Vivek Rajan6-Jun-01 20:00 
GeneralRe: What's wrong with my code? (class template) Pin
Li Lirong6-Jun-01 21:02
Li Lirong6-Jun-01 21:02 
GeneralRe: What's wrong with my code? (class template) Pin
7-Jun-01 4:23
suss7-Jun-01 4:23 
GeneralRe: What's wrong with my code? (class template) Pin
Ghazi H. Wadi7-Jun-01 14:36
Ghazi H. Wadi7-Jun-01 14:36 
GeneralRe: What's wrong with my code? (class template) Pin
Li Lirong7-Jun-01 17:09
Li Lirong7-Jun-01 17:09 

Thank all.

Wink | ;)

I have try it in
C++ Builder. It runs well there.


I could have
defined the function within the class declaration. However, I am not able to do
that. The reason is illustrated by the following example. In the example, A<T>::nested uses B<T> and B<T>::nested used A<T>.


// begin of A.h

#pragma once


 


 // foreword
declaration, but we still can not use class B.

//that is why I can't put the definition of A<T>::nested::test() inside
the declaration;


template <class T> class B;


 


template <class
T> class A


{


public:


   
class nested


   
{


     
public:


       
void test(B<T> b);


   
};


  
nested GetNested() const


   
{



return nested();



   
}


}


#include A.imp


// end of A.h


 


//A.imp


#pragma once


#include B.h //
now we can use class B


template <class
T> void A<T>::nested::test( B<T> b)


{


       
b.GetNested();


}


 


//end of A.imp


 


//begin of A.cpp


#include A.h //the
only one line in A.cpp


//end of A.cpp


 


 


// B.h

#pragma once


 


 // foreword
declaration, but we still can not use class A.

//that is why I can't put the definition of B<T>::nested::test() inside
the declaration;


template <class
T> class A; // foreword declaration


template <class
T> class B


{


public:


   
class nested


   
{


     
public:


       
void test(A<T> b);


   
};


  
nested GetNested() const


   
{



return nested();



   
}


}


#include B.imp


// end of B.h


 


//B.imp


#pragma once


#include A.h


template <class
T> void B<T>::nested::test( A<T> a)


{



a.GetNested();



}


 


//end of B.imp


 


//begin of B.cpp


#include B.h //the
only one line in B.cpp


//end of B.cpp


 


The result is that
this situation force me not to use nested class.


What a pity. My
logical design is forced to change by a bug.;( Or I have to change my compiler.






Lirong
GeneralRe: What's wrong with my code? (class template) Pin
Jim Crafton7-Jun-01 18:57
Jim Crafton7-Jun-01 18:57 
GeneralScrolling the content Pin
Mangesh Sardesai6-Jun-01 18:55
Mangesh Sardesai6-Jun-01 18:55 
GeneralJoystick / Gamepad Pin
6-Jun-01 16:50
suss6-Jun-01 16:50 
GeneralRe: Joystick / Gamepad Pin
Christian Graus6-Jun-01 16:56
protectorChristian Graus6-Jun-01 16:56 
GeneralRe: Joystick / Gamepad Pin
7-Jun-01 10:36
suss7-Jun-01 10:36 
GeneralPut Enter character !!! Pin
Hadi Rezaee6-Jun-01 16:40
Hadi Rezaee6-Jun-01 16:40 
GeneralRe: Put Enter character !!! Pin
Christian Graus6-Jun-01 16:57
protectorChristian Graus6-Jun-01 16:57 
GeneralRe: Really? Pin
Masaaki Onishi6-Jun-01 17:15
Masaaki Onishi6-Jun-01 17:15 
GeneralRe: Really? Pin
Christian Graus6-Jun-01 17:43
protectorChristian Graus6-Jun-01 17:43 
GeneralRe: Put Enter character !!! Pin
Vivek Rajan6-Jun-01 20:13
Vivek Rajan6-Jun-01 20:13 
Generalinsert bitmap in a MDI child window Pin
Pou6-Jun-01 15:58
Pou6-Jun-01 15:58 
GeneralRe: insert bitmap in a MDI child window Pin
Christian Graus6-Jun-01 16:22
protectorChristian Graus6-Jun-01 16:22 
GeneralRe: insert bitmap in a MDI child window Pin
Tomasz Sowinski6-Jun-01 23:42
Tomasz Sowinski6-Jun-01 23:42 
Generala bitmap to click in a MDI child window Pin
Pou6-Jun-01 15:57
Pou6-Jun-01 15:57 
GeneralRe: a bitmap to click in a MDI child window Pin
Christian Graus6-Jun-01 16:23
protectorChristian Graus6-Jun-01 16:23 
Generalcd rom drive letter Pin
Pou6-Jun-01 15:54
Pou6-Jun-01 15:54 
GeneralReally Silly Question I Think Pin
William Bartholomew6-Jun-01 14:33
William Bartholomew6-Jun-01 14:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.