Click here to Skip to main content
15,893,161 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: vector of template class Pin
Richard MacCutchan18-Aug-10 9:44
mveRichard MacCutchan18-Aug-10 9:44 
GeneralRe: vector of template class Pin
forwardsim18-Aug-10 10:08
forwardsim18-Aug-10 10:08 
AnswerRe: vector of template class Pin
Aescleal18-Aug-10 10:10
Aescleal18-Aug-10 10:10 
GeneralRe: vector of template class Pin
forwardsim18-Aug-10 10:34
forwardsim18-Aug-10 10:34 
GeneralRe: vector of template class Pin
Aescleal18-Aug-10 11:11
Aescleal18-Aug-10 11:11 
GeneralRe: vector of template class Pin
forwardsim18-Aug-10 11:02
forwardsim18-Aug-10 11:02 
AnswerRe: vector of template class Pin
Niklas L18-Aug-10 10:30
Niklas L18-Aug-10 10:30 
GeneralRe: vector of template class [modified] Pin
forwardsim18-Aug-10 10:54
forwardsim18-Aug-10 10:54 
Hi,

It was my first work around test. Unfortunately, it didn't work because I wasn't able to
down-cast from the parent class to the child class. I guess the problem arise only when a member
function has the template class in argument...

Here what happens.

class base
{
  // virtual void add( ?????????????? )=0;
};

template< class T >
class CTest : public base
{
public:
   T mem;
   void add( CTest< T > i )
   {
      // same type for this and i
      // add
      mem += i.mem;
   }

   template < class S >
   void add( CTest< S > i )
   {
     // not same type for this and i
     // do nothing
   }
};

std::vector<base*> all;

CTest< int > a;
CTest< double > b;

all.push( (base*) &a );
all.push( (base*) &b );

// the next line will not work since base doesn't implement add.
// how to make add virtual to be able to link it to the child add ????????
// I tried few things without success...
all[0]->add( all[1] );


I hope my example is clear enough...

SV.

modified on Wednesday, August 18, 2010 5:03 PM

GeneralRe: vector of template class Pin
Aescleal18-Aug-10 11:40
Aescleal18-Aug-10 11:40 
GeneralRe: vector of template class Pin
forwardsim18-Aug-10 12:22
forwardsim18-Aug-10 12:22 
GeneralRe: vector of template class Pin
Aescleal18-Aug-10 22:15
Aescleal18-Aug-10 22:15 
GeneralRe: vector of template class Pin
Emilio Garavaglia18-Aug-10 22:23
Emilio Garavaglia18-Aug-10 22:23 
GeneralRe: vector of template class Pin
forwardsim19-Aug-10 4:44
forwardsim19-Aug-10 4:44 
AnswerRe: vector of template class Pin
Niklas L19-Aug-10 2:23
Niklas L19-Aug-10 2:23 
GeneralRe: vector of template class Pin
Aescleal19-Aug-10 3:01
Aescleal19-Aug-10 3:01 
GeneralRe: vector of template class Pin
Niklas L19-Aug-10 3:16
Niklas L19-Aug-10 3:16 
GeneralRe: vector of template class Pin
forwardsim19-Aug-10 4:47
forwardsim19-Aug-10 4:47 
GeneralRe: vector of template class Pin
Aescleal19-Aug-10 6:24
Aescleal19-Aug-10 6:24 
GeneralRe: vector of template class Pin
Niklas L19-Aug-10 8:29
Niklas L19-Aug-10 8:29 
GeneralRe: vector of template class [modified] Pin
Paul Michalik20-Aug-10 2:03
Paul Michalik20-Aug-10 2:03 
GeneralRe: vector of template class Pin
Niklas L20-Aug-10 2:22
Niklas L20-Aug-10 2:22 
GeneralRe: vector of template class Pin
Paul Michalik20-Aug-10 4:06
Paul Michalik20-Aug-10 4:06 
Questioncan main() be overloaded?? Pin
AmbiguousName18-Aug-10 6:36
AmbiguousName18-Aug-10 6:36 
AnswerRe: can main() be overloaded?? Pin
Aescleal18-Aug-10 6:50
Aescleal18-Aug-10 6:50 
QuestionRe: can main() be overloaded?? Pin
David Crow18-Aug-10 9:14
David Crow18-Aug-10 9:14 

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.