Some bug
Maciej Hrebien
scoopy81@box43.gnet.pl
Mon Jan 24 06:51:00 GMT 2000
Hi!
OS: RedHat Linux 6.0 with kernel: 2.2.5-15
egcs, egcs-c++ and cpp with version 1.1.2-12
And I use KDE.
I was learning exception handling and I wrote some example programm with
a little mistake. When I was compilling it my disk was working hard and
then the system stopped. After restart I found the mistake, recompiled
the program and all was OK. The programm is attached to this mail.
// The mistake is in template class pointer.
Before my system stopped I sow the compiler message:
In instantiation of 'pointer<int>':
instantiated from here
invalid use of undefined type 'class pointer<int>'
and that was in line 65.
So, that's all.
I look forward to hearing from You.
--
CU || BFN
Maciek
PS: Sorry for my English :)
#include <iostream.h>
void fun_bibl();
///////////////////////////////////////////////////////////////////////////////
template<class typ>
class pointer_1
{
typ* adres;
public:
pointer_1(int rozmiar)
{ adres=new typ[rozmiar];
cout<<"wkladam do pamieci..."<<endl;
}
~pointer_1()
{ cout<<"usuwam z pamieci"<<endl;
delete [] adres;
}
typ& operator*()
{
return *adres;
}
typ& operator[](int ktory)
{
return *(adres+ktory);
}
};
//*****************************************************************************
template<class typ>
class pointer
{
pointer<typ> wskaznik; //wrong!!! pointer_1<typ> wskaznik; is correct!
public:
pointer(int rozmiar=1):wskaznik(rozmiar)
{ cout<<"kosrt. wskaznika"<<endl;
fun_bibl();
}
~pointer()
{ cout<<"destr. wskaznika..."<<endl;
}
typ& operator*()
{
return *wskaznik;
}
typ& operator[](int ktory)
{
return wskaznik[ktory];
}
};
///////////////////////////////////////////////////////////////////////////////
void fun_bibl()
{
cout<<"Sytuacja wyjatkowa? t/n ";
char odp;
cin>>odp;
if(odp=='t')
{
cout<<"Rzucam wyjatek z jakiejs fun. bibliotecznej\n";
throw 1;
}
}
///////////////////////////////////////////////////////////////////////////////
void main()
{
try{
cout<<"Blok try..."<<endl;
pointer<int> wsk;
*wsk=99;
cout<<*wsk<<endl;
pointer<int> tab(100);
tab[55]=999;
cout<<tab[55]<<endl;
// jakies dalsze instrukcje...
}
catch(int)
{
cout<<"Jakis wyjatek typu int..."<<endl;
}
}
More information about the Gcc-bugs
mailing list