public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Michael Ben-Gershon <mybg@netvision.net.il>
To: help-gcc@gnu.org
Subject: Template problem
Date: Tue, 28 Dec 1999 13:11:00 -0000	[thread overview]
Message-ID: <38691EC2.598C836F@netvision.net.il> (raw)

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

WARNING: multiple messages have this Message-ID
From: Michael Ben-Gershon <mybg@netvision.net.il>
To: help-gcc@gnu.org
Subject: Template problem
Date: Fri, 31 Dec 1999 22:24:00 -0000	[thread overview]
Message-ID: <38691EC2.598C836F@netvision.net.il> (raw)
Message-ID: <19991231222400.HGNblgcy2qCO4VRV2IG0l3JYHolaxTUcj_d37RHt0no@z> (raw)

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

             reply	other threads:[~1999-12-28 13:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-28 13:11 Michael Ben-Gershon [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=38691EC2.598C836F@netvision.net.il \
    --to=mybg@netvision.net.il \
    --cc=help-gcc@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).