* Template problem
@ 1999-12-28 13:11 Michael Ben-Gershon
1999-12-31 22:24 ` Michael Ben-Gershon
2000-01-02 4:22 ` Alex Vinokur
0 siblings, 2 replies; 9+ messages in thread
From: Michael Ben-Gershon @ 1999-12-28 13:11 UTC (permalink / raw)
To: help-gcc
I am having problems with templates on gcc-2.95.2. I am sure
that the code worked on some earlier version of gcc, but I
don't recall exactly which version it was.
I have a Range class defined as:
template <class T, T lower, T upper>
class Range
{
...
};
It has a number of non-member functions defined for the various
operators. In particular, it has the following defined:
template<class T, T lower, T upper>
ostream&
operator<< (ostream& out_stream, const Range<T, lower, upper>& the_value);
In the main program, I have
int main()
{
Range<int, -5, 5> f = -5;
cout << endl;
cout << "Number is: " << f << endl;
...
When compiling (all the code, including the implementation of the
function above, is in one file) I get the following error:
test_range.cc: In function `int main()':
test_range.cc:18: no match for `ostream & << Range<int,-5,5> &'
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/iostream.h:77:
candidates are: class ostream & ostream::operator <<(char)
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/iostream.h:78:
class ostream & ostream::operator <<(unsigned char)
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/iostream.h:79:
class ostream & ostream::operator
etc, etc, etc ...
The strange thing is that I have a derived class, which behaves fine!
It is defined as:
template<int lowest, int highest>
class Floor_Number : public Range<int, lowest, highest>
{
...
};
With the ostream stuff defined as:
template<int lowest, int highest>
ostream&
operator<< (ostream& out_stream, const Floor_Number<lowest, highest>&
the_value);
and is used in the test program as:
Floor_Number<-3, 10> Ff = -5;
cout << "The floor is: " << Ff << endl;
What is wrong with the Range stuff? If it is wrong, how is it that the derived
class Floor_Number is OK?
Thanks,
Michael Ben-Gershon
mybg@netvision.net.il
^ permalink raw reply [flat|nested] 9+ messages in thread
* Template problem
1999-12-28 13:11 Template problem Michael Ben-Gershon
@ 1999-12-31 22:24 ` Michael Ben-Gershon
2000-01-02 4:22 ` Alex Vinokur
1 sibling, 0 replies; 9+ messages in thread
From: Michael Ben-Gershon @ 1999-12-31 22:24 UTC (permalink / raw)
To: help-gcc
I am having problems with templates on gcc-2.95.2. I am sure
that the code worked on some earlier version of gcc, but I
don't recall exactly which version it was.
I have a Range class defined as:
template <class T, T lower, T upper>
class Range
{
...
};
It has a number of non-member functions defined for the various
operators. In particular, it has the following defined:
template<class T, T lower, T upper>
ostream&
operator<< (ostream& out_stream, const Range<T, lower, upper>& the_value);
In the main program, I have
int main()
{
Range<int, -5, 5> f = -5;
cout << endl;
cout << "Number is: " << f << endl;
...
When compiling (all the code, including the implementation of the
function above, is in one file) I get the following error:
test_range.cc: In function `int main()':
test_range.cc:18: no match for `ostream & << Range<int,-5,5> &'
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/iostream.h:77:
candidates are: class ostream & ostream::operator <<(char)
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/iostream.h:78:
class ostream & ostream::operator <<(unsigned char)
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/iostream.h:79:
class ostream & ostream::operator
etc, etc, etc ...
The strange thing is that I have a derived class, which behaves fine!
It is defined as:
template<int lowest, int highest>
class Floor_Number : public Range<int, lowest, highest>
{
...
};
With the ostream stuff defined as:
template<int lowest, int highest>
ostream&
operator<< (ostream& out_stream, const Floor_Number<lowest, highest>&
the_value);
and is used in the test program as:
Floor_Number<-3, 10> Ff = -5;
cout << "The floor is: " << Ff << endl;
What is wrong with the Range stuff? If it is wrong, how is it that the derived
class Floor_Number is OK?
Thanks,
Michael Ben-Gershon
mybg@netvision.net.il
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Template problem
1999-12-28 13:11 Template problem Michael Ben-Gershon
1999-12-31 22:24 ` Michael Ben-Gershon
@ 2000-01-02 4:22 ` Alex Vinokur
2000-04-01 0:00 ` Alex Vinokur
1 sibling, 1 reply; 9+ messages in thread
From: Alex Vinokur @ 2000-01-02 4:22 UTC (permalink / raw)
To: help-gcc
In article <38691EC2.598C836F@netvision.net.il>,
Michael Ben-Gershon <mybg@netvision.net.il> wrote:
> I am having problems with templates on gcc-2.95.2. I am sure
> that the code worked on some earlier version of gcc, but I
> don't recall exactly which version it was.
>
> I have a Range class defined as:
>
> template <class T, T lower, T upper>
> class Range
> {
> ...
> };
>
> It has a number of non-member functions defined for the various
> operators. In particular, it has the following defined:
>
> template<class T, T lower, T upper>
> ostream&
> operator<< (ostream& out_stream, const Range<T, lower, upper>&
the_value);
>
> In the main program, I have
>
> int main()
> {
> Range<int, -5, 5> f = -5;
>
> cout << endl;
>
> cout << "Number is: " << f << endl;
> ...
>
> When compiling (all the code, including the implementation of the
> function above, is in one file) I get the following error:
>
> test_range.cc: In function `int main()':
> test_range.cc:18: no match for `ostream & << Range<int,-5,5> &'
>
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/iostream.h:77:
> candidates are: class ostream & ostream::operator <<(char)
>
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/iostream.h:78:
> class ostream & ostream::operator <<(unsigned char)
>
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/iostream.h:79:
> class ostream & ostream::operator
>
> etc, etc, etc ...
>
> The strange thing is that I have a derived class, which behaves fine!
> It is defined as:
>
> template<int lowest, int highest>
> class Floor_Number : public Range<int, lowest, highest>
> {
> ...
> };
>
> With the ostream stuff defined as:
>
> template<int lowest, int highest>
> ostream&
> operator<< (ostream& out_stream, const Floor_Number<lowest, highest>&
> the_value);
>
> and is used in the test program as:
>
> Floor_Number<-3, 10> Ff = -5;
>
> cout << "The floor is: " << Ff << endl;
>
> What is wrong with the Range stuff? If it is wrong, how is it that the
derived
> class Floor_Number is OK?
>
> Thanks,
>
> Michael Ben-Gershon
> mybg@netvision.net.il
>
The following code has no problem when
compiling on g++ (egcs-2.91.5).
Alex
//#########################################################
//------------------- C++ code : BEGIN -------------------
#include <iostream>
//-----------------------------------
template <class T, T lower, T upper>
class Range
{
public :
T value_;
Range (const T& value_i)
{
value_ = value_i;
}
};
//-----------------------------------
template<class T, T lower, T upper>
ostream&
operator<< (ostream& out_stream, const Range<T, lower, upper>&
the_value)
{
return out_stream << the_value.value_;
}
//-----------------------------------
int main()
{
Range<int, -3, 5> f (-2);
cout << endl;
cout << "Number is: " << f << endl;
return 0;
}
//------------------- C++ code : END ----------------------
//#########################################################
//------------------- Running Results : BEGIN -------------
Number is: -2
//------------------- Running Results : END ---------------
//#########################################################
//------------------- Environment -------------------------
g++ -v : gcc version egcs-2.91.57 19980901
(egcs-1.1 release)
uname -sr : SunOS 5.6
//---------------------------------------------------------
//#########################################################
Sent via Deja.com http://www.deja.com/
Before you buy.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Template problem
2000-01-02 4:22 ` Alex Vinokur
@ 2000-04-01 0:00 ` Alex Vinokur
0 siblings, 0 replies; 9+ messages in thread
From: Alex Vinokur @ 2000-04-01 0:00 UTC (permalink / raw)
To: help-gcc
In article <38691EC2.598C836F@netvision.net.il>,
Michael Ben-Gershon <mybg@netvision.net.il> wrote:
> I am having problems with templates on gcc-2.95.2. I am sure
> that the code worked on some earlier version of gcc, but I
> don't recall exactly which version it was.
>
> I have a Range class defined as:
>
> template <class T, T lower, T upper>
> class Range
> {
> ...
> };
>
> It has a number of non-member functions defined for the various
> operators. In particular, it has the following defined:
>
> template<class T, T lower, T upper>
> ostream&
> operator<< (ostream& out_stream, const Range<T, lower, upper>&
the_value);
>
> In the main program, I have
>
> int main()
> {
> Range<int, -5, 5> f = -5;
>
> cout << endl;
>
> cout << "Number is: " << f << endl;
> ...
>
> When compiling (all the code, including the implementation of the
> function above, is in one file) I get the following error:
>
> test_range.cc: In function `int main()':
> test_range.cc:18: no match for `ostream & << Range<int,-5,5> &'
>
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/iostream.h:77:
> candidates are: class ostream & ostream::operator <<(char)
>
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/iostream.h:78:
> class ostream & ostream::operator <<(unsigned char)
>
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/iostream.h:79:
> class ostream & ostream::operator
>
> etc, etc, etc ...
>
> The strange thing is that I have a derived class, which behaves fine!
> It is defined as:
>
> template<int lowest, int highest>
> class Floor_Number : public Range<int, lowest, highest>
> {
> ...
> };
>
> With the ostream stuff defined as:
>
> template<int lowest, int highest>
> ostream&
> operator<< (ostream& out_stream, const Floor_Number<lowest, highest>&
> the_value);
>
> and is used in the test program as:
>
> Floor_Number<-3, 10> Ff = -5;
>
> cout << "The floor is: " << Ff << endl;
>
> What is wrong with the Range stuff? If it is wrong, how is it that the
derived
> class Floor_Number is OK?
>
> Thanks,
>
> Michael Ben-Gershon
> mybg@netvision.net.il
>
The following code has no problem when
compiling on g++ (egcs-2.91.5).
Alex
//#########################################################
//------------------- C++ code : BEGIN -------------------
#include <iostream>
//-----------------------------------
template <class T, T lower, T upper>
class Range
{
public :
T value_;
Range (const T& value_i)
{
value_ = value_i;
}
};
//-----------------------------------
template<class T, T lower, T upper>
ostream&
operator<< (ostream& out_stream, const Range<T, lower, upper>&
the_value)
{
return out_stream << the_value.value_;
}
//-----------------------------------
int main()
{
Range<int, -3, 5> f (-2);
cout << endl;
cout << "Number is: " << f << endl;
return 0;
}
//------------------- C++ code : END ----------------------
//#########################################################
//------------------- Running Results : BEGIN -------------
Number is: -2
//------------------- Running Results : END ---------------
//#########################################################
//------------------- Environment -------------------------
g++ -v : gcc version egcs-2.91.57 19980901
(egcs-1.1 release)
uname -sr : SunOS 5.6
//---------------------------------------------------------
//#########################################################
Sent via Deja.com http://www.deja.com/
Before you buy.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: template problem
[not found] <2F05A390F72A0A409390E016D23E45E8042DBE10@ns-bco-mse4.im.battelle.org>
@ 2002-10-09 11:46 ` andy
0 siblings, 0 replies; 9+ messages in thread
From: andy @ 2002-10-09 11:46 UTC (permalink / raw)
To: gcc-help
Thanks to all who responded.
typename did indeed fix it.
Regards
Andy
On 10/9/02 10:12 AM, "Moore, Mathew L" wrote:
> The compiler doesn't realize that _DataType is a typename within DataClass
> (it could, after all, be a function or variable), so you have to explicitly
> tell it. This is accomplished using the "typename" keyword:
>
> template <class FilterClass, class DataClass>
> class P2PassScale
> {
> public:
> typedef typename DataClass::_DataType _DataType;
> ...
>
>
>
>> -----Original Message-----
>> From: andy [mailto:andy@softbook.com]
>> Sent: Wednesday, October 09, 2002 12:34
>> To: gcc-help@gcc.gnu.org
>> Subject: template problem
>>
>>
>> I'm having trouble compiling the following in gcc3.2:
>>
>> template <class FilterClass, class DataClass = CDataCOLORREF>
>>
>> class C2PassScale
>> {
>> public:
>> typedef DataClass::_DataType _DataType; //ERROR -see below
>> typedef DataClass::_RowType _RowType;
>> ....
>>
>>
>> //class CDataCOLORREF is declared below in the same file
>> class CDataCOLORREF {
>> public:
>> typedef unsigned long_DataType;
>> ....
>>
>> ERROR above reads:
>> "ISO C++ forbids declaration of _DataType with no type"
>>
>> Now, if I understand the code correctly, the _DataType
>> variable of the
>> C2PassScale class is typedef'ed to be the same as _DataType
>> variable of the
>> the CDataCOLORREF class, i.e, long.
>> It looks like gcc cannot figure out what type the _DataType
>> variable of
>> C2PassScale class needs to be.
>> I wonder if anyone can help finding a workaround or maybe a
>> compile option I
>> need to turn on
>>
>> Thanks in advance
>> Andy
>>
>>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: template problem
2002-10-09 9:33 template problem andy
@ 2002-10-09 10:18 ` Eljay Love-Jensen
0 siblings, 0 replies; 9+ messages in thread
From: Eljay Love-Jensen @ 2002-10-09 10:18 UTC (permalink / raw)
To: andy, gcc-help
Hi Andy,
Try this...
class C2PassScale
{
public:
typedef typename DataClass::_DataType _DataType;
typedef typename DataClass::_RowType _RowType;
....
The problem should go away.
--Eljay
^ permalink raw reply [flat|nested] 9+ messages in thread
* template problem
@ 2002-10-09 9:33 andy
2002-10-09 10:18 ` Eljay Love-Jensen
0 siblings, 1 reply; 9+ messages in thread
From: andy @ 2002-10-09 9:33 UTC (permalink / raw)
To: gcc-help
I'm having trouble compiling the following in gcc3.2:
template <class FilterClass, class DataClass = CDataCOLORREF>
class C2PassScale
{
public:
typedef DataClass::_DataType _DataType; //ERROR -see below
typedef DataClass::_RowType _RowType;
....
//class CDataCOLORREF is declared below in the same file
class CDataCOLORREF {
public:
typedef unsigned long_DataType;
....
ERROR above reads:
"ISO C++ forbids declaration of _DataType with no type"
Now, if I understand the code correctly, the _DataType variable of the
C2PassScale class is typedef'ed to be the same as _DataType variable of the
the CDataCOLORREF class, i.e, long.
It looks like gcc cannot figure out what type the _DataType variable of
C2PassScale class needs to be.
I wonder if anyone can help finding a workaround or maybe a compile option I
need to turn on
Thanks in advance
Andy
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Template problem
2001-04-02 7:20 jpyubero
@ 2001-04-02 21:00 ` Alexandre Oliva
0 siblings, 0 replies; 9+ messages in thread
From: Alexandre Oliva @ 2001-04-02 21:00 UTC (permalink / raw)
To: jpyubero; +Cc: gcc-help
On Apr 2, 2001, jpyubero <gva09@elai.upm.es> wrote:
> Image.hh:31: return type specified for `operator XVImage<float>'
> XVImage<float> operator XVImage<float>()
So, the code is ill-formed, and GCC tells you what the problem is.
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me
^ permalink raw reply [flat|nested] 9+ messages in thread
* Template problem
@ 2001-04-02 7:20 jpyubero
2001-04-02 21:00 ` Alexandre Oliva
0 siblings, 1 reply; 9+ messages in thread
From: jpyubero @ 2001-04-02 7:20 UTC (permalink / raw)
To: gcc-help
Hi,
I compiled the program Xvision perfetly under RedHat, but now I`ve
install Mandrake and It's no possible.
When I typing make the exit is:
make
g++ -g -I- -I. -I~/xvision/include -I~/xvision -w -c prueba.cxx -o prueba.o
In file included from Video.hh:41,
from CWindow.hh:34,
from BasicFeature.hh:37,
from FTypes.hh:32,
from Line.hh:33,
from prueba.cxx:5:
Image.hh:31: return type specified for `operator XVImage<float>'
make: *** [prueba.o] Error 1
The file Image.hh is:
#ifndef Image_hh
#define Image_hh
#include "Tracker.hh"
#include "XVImage.hh"
class Image : public XVImage<int>
{
public:
Image (int ncols_in = 0, int nrows_in = 0)
: XVImage<int>(nrows_in, ncols_in)
{}
Image (XVImage<int>& im)
: XVImage<int>(im)
{}
#if (XV_OS == XV_IRIX)
operator XVImage<float>() {
float* floatData = new float[storesize];
for (int i = 0; i < storesize; i++)
floatData[i] = (float)image[i];
XVImage<float> newImage(nrows, ncols, floatData
delete floatData;
return newImage;
}
#else
XVImage<float> operator XVImage<float>()
{ //Number of line 31
float* floatData = new float[storesize];
for (int i = 0; i < storesize; i++)
floatData[i] = (float)image[i];
XVImage<float> newImage(nrows, ncols, floatData
delete floatData;
return newImage;
}
#endif
};
#endif Image_hh
And the lines where is implemented in another file is:
template <class T> XVImage<T> &operator >>(const ColVector &x,XVImage<T> &y);
template <class T> XVImage<T> &operator >>(const RowVector &x,XVImage<T> &y);
Can anyboby help me?
Sorry for my english
Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2002-10-09 18:46 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-28 13:11 Template problem Michael Ben-Gershon
1999-12-31 22:24 ` Michael Ben-Gershon
2000-01-02 4:22 ` Alex Vinokur
2000-04-01 0:00 ` Alex Vinokur
2001-04-02 7:20 jpyubero
2001-04-02 21:00 ` Alexandre Oliva
2002-10-09 9:33 template problem andy
2002-10-09 10:18 ` Eljay Love-Jensen
[not found] <2F05A390F72A0A409390E016D23E45E8042DBE10@ns-bco-mse4.im.battelle.org>
2002-10-09 11:46 ` andy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).