472,373 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

template class compiling problem

I'm trying to write a tree class and I've just stumbled on a compiling
problem. The compiler throws an error on a piece of code which to my eyes
it is error-free. Can anyone help me with this?

Here is the error message:

<error>
/home/rui/development/C++/mytree/src/tree.h:154: error: expected
constructor, destructor, or type conversion before ?&? token
</error>
Here is the code snippet:

<code>
template <class tData>
class tree
{
public:
//snip
class navigator
{
//snip
public:
navigator();
navigator(const navigator&);
~navigator();

//snip

navigator &operator= (const tree<tData> &);
};

};

//snip

template <class tData>
//the offending line: line 154
tree<tData>::navigator &tree<tData>::navigator::operator= (const tree<tData>
&pointed_node)
{
//snip
}
</code>
Thanks in advance
Rui Maciel
--
Running Kubuntu 5.10 with KDE 3.5.1 and proud of it.
jabber:ru********@jabber.org
Feb 12 '06 #1
4 1572
Rui Maciel wrote:
I'm trying to write a tree class and I've just stumbled on a compiling
problem. The compiler throws an error on a piece of code which to my
eyes it is error-free. Can anyone help me with this?

Here is the error message:

<error>
/home/rui/development/C++/mytree/src/tree.h:154: error: expected
constructor, destructor, or type conversion before ?&? token
</error>
Here is the code snippet:

<code>
template <class tData>
class tree
{
public:
//snip
class navigator
{
//snip
public:
navigator();
navigator(const navigator&);
~navigator();

//snip

navigator &operator= (const
tree<tData> &); };

};

//snip

template <class tData>
//the offending line: line 154
tree<tData>::navigator &tree<tData>::navigator::operator= (const
Add "typename " at the beginning.
tree<tData> &pointed_node)
{
//snip
}
</code>


V
--
Please remove capital As from my address when replying by mail
Feb 12 '06 #2
Victor Bazarov wrote:
template <class tData>
//the offending line: line 154
tree<tData>::navigator &tree<tData>::navigator::operator= (const


Add "typename " at the beginning.
tree<tData> &pointed_node)
{
//snip
}
</code>


V


Thanks Victor! That did it. Now it compiles perfecly.

But what's the logic behind the "typename" keyword? Why should it be used in
that situation?
Thanks once again for the help Victor.
Rui Maciel
--
Running Kubuntu 5.10 with KDE 3.5.1 and proud of it.
jabber:ru********@jabber.org
Feb 12 '06 #3

"Rui Maciel" <ru********@gmail.com> wrote in message
news:43***********************@news.telepac.pt...
Victor Bazarov wrote:
template <class tData>
//the offending line: line 154
tree<tData>::navigator &tree<tData>::navigator::operator= (const


Add "typename " at the beginning.
tree<tData> &pointed_node)
{
//snip
}
</code>


V


Thanks Victor! That did it. Now it compiles perfecly.

But what's the logic behind the "typename" keyword? Why should it be used
in
that situation?


The "typename" keyword, in this case, tells the compiler that navigator is a
type. Without typename, it could be mistaken for a static member of tree.

Regards,
Sumit.
--
Sumit Rajan <su****@msdc.hcltech.com>
Feb 13 '06 #4
Rui Maciel wrote:
Victor Bazarov wrote:

template <class tData>
//the offending line: line 154
tree<tData>::navigator &tree<tData>::navigator::operator= (const


Add "typename " at the beginning.

tree<tData> &pointed_node)
{
//snip
}
</code>


V

Thanks Victor! That did it. Now it compiles perfecly.

But what's the logic behind the "typename" keyword? Why should it be used in
that situation?


There is the possibility that tree<>::navigator is not a type. Although
tree<>::navigator is defined above, tree<> could possibly be specialized
such that tree<>::navigator did not exist or was something else.

typename reassures the compiler that you really did mean a type, since
tree<>::navigator is technically not defined until point of instantiation.

Hope that makes it clearer?
Calum
Feb 13 '06 #5

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

Similar topics

0
by: Leslaw Bieniasz | last post by:
Cracow, 16.09.2004 Hi, I have a problem with compiling the following construction involving cross-calls of class template methods, with additional inheritance. I want to have three class...
4
by: Thomi Richards | last post by:
Hi, I'm trying to create a simple stack class using C++ and templates. Everything works well and good if I amke the class totally inline. However, as soon as I try to seperate the class into a...
2
by: pagekb | last post by:
Hello, I'm having some difficulty compiling template classes as containers for other template objects. Specifically, I have a hierarchy of template classes that contain each other. Template...
6
by: B. Williams | last post by:
I have a problem dealing with class template where I was to write a class and after submitting the class, this is the feedback I got back from the instructor. I don't really understand it. Can...
45
by: charles.lobo | last post by:
Hi, I have recently begun using templates in C++ and have found it to be quite useful. However, hearing stories of code bloat and assorted problems I decided to write a couple of small programs...
8
by: nishit.gupta | last post by:
I was having a problem with template class memer function definition , so i serched the net and find that template class member fuction definition should be in header file else compilation will...
6
by: bogus1one | last post by:
Hi All Given the following: // NamespaceTemplate.cpp : Defines the entry point for the console application. // #include "stdafx.h"
3
by: nick4ng | last post by:
If I have a templated constructor, there is a way to know, at compile time, the instance when compiling the destructor? To be clearer my problem is that I have a templated constructor that is...
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.