473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to declare this template operator?

Hi all,

What is wrong with my following codes?
//SortedListOfEvents.hh
....
line 45: template < class Element > class SortedListOfEvents {
....
line 50: template <class Element>
friend ostream& operator << (ostream&, const
SortedListOfEvents < Element > &);

public:
....
private:
....
}

I always got the error messages like:

"SortedListOfEvents.hh": SortedListOfEvents.hh error: declaration of
'class Element' at line 50
"SortedListOfEvents.hh": SortedListOfEvents.hh error: shadows template
parm 'class Element' at line 45
Many thanks,

Patricia

Jan 26 '06 #1
3 1968
Patricia wrote:
Hi all,

What is wrong with my following codes?
//SortedListOfEvents.hh
...
line 45: template < class Element > class SortedListOfEvents {
...
line 50: template <class Element>
friend ostream& operator << (ostream&, const
SortedListOfEvents < Element > &);

public:
....
private:
....
}

I always got the error messages like:

"SortedListOfEvents.hh": SortedListOfEvents.hh error: declaration of
'class Element' at line 50
"SortedListOfEvents.hh": SortedListOfEvents.hh error: shadows template
parm 'class Element' at line 45
Many thanks,

Patricia


The problem is that you use the same template parameter name (viz.
Element) in both your class and your function. However, even if you
fixed that by renaming the friend function's template parameter
"Element2", it wouldn't link. See this FAQ for the solution:

http://www.parashift.com/c++-faq-lit...html#faq-35.16

Cheers! --M

Jan 26 '06 #2
The strange thing is these codes were compiled successfully by Sun CC.
Does the error depends on the compiler?

Jan 27 '06 #3
Patricia wrote:
The strange thing is these codes were compiled successfully by Sun CC.
Does the error depends on the compiler?


Please quote the message you are replying to. It makes things easier to
follow for those not using Goggle Groups. (To quote in Google Groups,
click on "show options" and then on "Reply" in the revealed header.)

Which code (note the singular) are you referring to? If the code with
Element2, did it *link* after compiling?

Cheers! --M

Jan 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
5
by: Oplec | last post by:
Hi, I am trying to figure out the correct syntax for declaring a friend function in a class template and then defining that member after the class. The code example below is what I am trying to get...
6
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for...
3
by: Chris | last post by:
I am having a very strange problem involving virtual functions in template classes. First of all, here is an extremely simplified structure of the two classes I am having problems with. ...
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
5
by: benben | last post by:
How do you declare a function f that takes a parameter that is a pointer to itself? So you can do f(f); Pardon my curiosity! Ben
3
by: jdurancomas | last post by:
Dear all, I'm trying to declare the operator++ to a nested class. The nested class is not template but the container it is. The code used in teh sample program is included bellow: ...
6
by: puzzlecracker | last post by:
Say we have this structure: Struct Foo{ .... friend ostream& operator << (ostream& s, Foo & m); ..... }; friend ostream& operator << (ostream& s, Foo & m){
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.