Thread View: pl.comp.objects
2 messages
2 total messages
Started by mme... Marek Meres
Fri, 22 Dec 1995 00:00
Re: Problem: function template in a class
Author: mme... Marek Meres
Date: Fri, 22 Dec 1995 00:00
Date: Fri, 22 Dec 1995 00:00
49 lines
1403 bytes
1403 bytes
Przeczytalem list Krzysztofa Halasy i nie wiem czy dobrze rozumiem
problem. Jestem swiezy w OOP, liscie i w ogole Internecie, wiec za
ewentualna ignorancje z gory przepraszam:
>
> Czesc,
>
> Jak cos takiego zrobic:
>
> class First
> {
> template <class ArgType> void Func(ArgType Arg);
> };
>
> Oczywiscie tak to nie przechodzi - nie rozumie ze w klasie moze byc template.
A moze ?
>
> Greetings,
> KHC
>
Chyba mozna ten problem (no wlasnie, jaki problem) rozwiazac standardowo:
#include <iostream.h>
template <class T>
class Test
{
public:
T pisz(T t) { cout<<t ; return t ; }
} ;
class T_int : public Test<int>
{} ;
void main()
{
T_int t1 ;
t1.pisz(1) ;
}
(sprawdzalem na BC 3.1)
Jakbys mogl Krzysiek, napisac dokladnie o co ci chodzi - chetnie bym
poszerzyl swoje horyzonty.
Marek Meres
P.S. A tak poza tym, to Wesolych Swiat wszystkim !
Re: Problem: function template in a class
Author: k... Krzysztof Halasa
Date: Fri, 22 Dec 1995 00:00
Date: Fri, 22 Dec 1995 00:00
51 lines
1702 bytes
1702 bytes
Marek Meres (mme...@zeus.polsl.gliwice.pl) wrote:
KH> > class First
> > {
> > template <class ArgType> void Func(ArgType Arg);
> > };
> Chyba mozna ten problem (no wlasnie, jaki problem) rozwiazac standardowo:
> #include <iostream.h>
> template <class T>
> class Test
> {
> public:
> T pisz(T t) { cout<<t ; return t ; }
> } ;
> class T_int : public Test<int>
> {} ;
> void main()
> {
> T_int t1 ;
> t1.pisz(1) ;
> }
> Jakbys mogl Krzysiek, napisac dokladnie o co ci chodzi - chetnie bym
> poszerzyl swoje horyzonty.
No tak, tak sie da to zrobic... Ale ja musze miec obiekty jednego typu,
czyli deklaracja musi byc np.:
{
First moja_klasa; // a raczej moja_klasa[];
// A potem musze robic
First.Func(10)
First.Func("qwerty");
First.Func('x');
}
Oczywiscie sam moge wyprodukowac wszystkie funkcje (nie jako templates), ale
chcialbym by komplikator zrobil mi to automatycznie.
Greetings,
KHC
--------------------------------------------------------------------
Krzysztof Halasa
Network Administrator of The Palace of Youth in Warsaw
Palac Mlodziezy Internet: k...@pm.waw.pl
ul. Swietokrzyska Fidonet: KHC, 2:480/40
00-901 Warsaw, Poland
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads