Re: [Dev-C++] Parametric polymorfizm
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jason H. <jas...@bt...> - 2001-10-24 00:16:23
|
Hi Vatay.
You forgot the typedefs in the header:
typedef counter<int> int_counter;
typedef counter<float> float_counter;
Hope this helps. The code you were using was actualy creating instances of
objects in the header, which is very bad.
Toodle-pip, Jason. ;)
----- Original Message -----
From: "Vatay" <va...@op...>
To: <dev...@li...>
Sent: Tuesday, October 23, 2001 1:31 PM
Subject: [Dev-C++] Parametric polymorfizm
Hi,
I have one litle problem, to this time only C projects written and slowly
become familiar with polimorfizm and here is my problem:
I can't asking my friends (all programmed in Delphi).
A have one litte example written and the compiler returned 7 errors!
what have I wrong written?
Thank,
Szeg,ny Leg,ny
Error message:
c:/devcpp/paramtr/main.cpp: In function `int main()':
c:/devcpp/paramtr/main.cpp:11: `int_count' undeclared (first use this
function)
c:/devcpp/paramtr/main.cpp:11: (Each undeclared identifier is reported only
once
c:/devcpp/paramtr/main.cpp:11: for each function it appears in.)
c:/devcpp/paramtr/main.cpp:11: parse error before `;'
c:/devcpp/paramtr/main.cpp:12: `float_counter' undeclared (first use this
function)
c:/devcpp/paramtr/main.cpp:14: `c1' undeclared (first use this function)
c:/devcpp/paramtr/main.cpp:15: `c2' undeclared (first use this function)
Sorce code's:
// FILE: main.cpp
//
// SNIP: parametrikus polimorfizmus
#include <stdio.h>
#include "count.h"
main()
{
int_count c1;
float_counter c2;
c1.put_value(5);
c2.put_value(5.5);
printf("\n c1 = %d", c1.access_value() );
printf("\n c2 = %f", c2.access_value() );
}
// FILE: count.h
template <class T> class counter
{
private:
T value;
public:
counter () { value = 0; }
void increment() { value++; }
void decrement() { if(value > 0) value--; }
T access_value() { return value; }
void put_value( T new_value) { value = new_value; }
};
typedef counter<int> int_counter;
typedef counter<float> float_counter;
----------------- Live long OPREA & the Net
This e-mail has been sent with OperaMail, as a free service from
Opera Software.
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|