delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/09/11/03:22:09

X-Originating-IP: [208.160.246.197]
From: "Nimrod Abing" <n_abing AT hotmail DOT com>
To: djgpp AT delorie DOT com
Subject: Re: Templates and virtual ?
Date: Mon, 11 Sep 2000 15:19:55 PHT
Mime-Version: 1.0
Message-ID: <F222UK4W4ZX8jAlHKkB000086f8@hotmail.com>
X-OriginalArrivalTime: 11 Sep 2000 07:19:56.0133 (UTC) FILETIME=[AFAC0150:01C01BC0]
Reply-To: djgpp AT delorie DOT com

>From: "Rafał Maj" <r_maj AT poczta DOT onet DOT pl>
>Reply-To: djgpp AT delorie DOT com
>To: djgpp AT delorie DOT com
>Subject: Templates and virtual ?
>Date: Fri, 8 Sep 2000 22:16:19 +0200
>
>Hi,
>why I cann't use virtual with templates, like this :
>
>class test { public :
>   template <class typ>
>   virtual void fun(typ var) {  }
>};
>
>thanks,
>Rafal
>

You should have given a more or less complete example here, but anyway:


template <class typ> // <- Use this at the top of a class definition.
class test {
public:
  virtual void fun(typ var) { }
  virtual void gun(typ var);
};

template <class typ> // <- Or at the top of a class method definition.
void test<typ>::gun(typ var)
{
  //. . .
}

this creates a generic class called `test' to actually use this template,
you will have to _instantiate_ it.

test<char> testobject;

...

testobject.fun('X');

Read a book on C++ programming about this. C++ the Language ?th Ed, by
Bjarne Strourstrup. I forget what edition I used, but check out the
latest edition if possible.

HTH.

----------------
_nimrod_a_abing_

+----------------------------------------------------+
|Homepage: http://www.geocities.com/n_abing/index.htm|
+----------------------------------------------------+

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019