Hi,
I want to implement an graph using templates.
In my header file I define the templates node and edge:
template <class NODE> class GNode
{
NODE *info;
public:
GraphNode();
void SetInfo(const NODE &x);
};
template <class EDGE> class GEdge
{
EDGE *info;
GNode<NODE> *source; // line 75
GNode<NODE> *target; // line 78
public:
GEdge<EDGE>(GNo de* newsource, GNode* newtarget); //line 81
[snip]
File graph.cpp:
[snip]
template <class EDGE>
GEdge<EDGE>::GE dge(GNode* newsource, GNode* newtarget)
{
src = newsource;
trg = newtarget;
info = NULL;
}
[snip]
But the compiler complains:
graph.h:75: type/value mismatch at argument 1 in template parameter list for
`template <class NODE> GNode<NODE>'
graph.h:75: expected a type, got `NODE'
graph.h:75: ANSI C++ forbids declaration `source' with no type
graph.h:78: type/value mismatch at argument 1 in template parameter list for
`template <class NODE> GNode<NODE>'
graph.h:78: expected a type, got `NODE'
graph.h:78: ANSI C++ forbids declaration `target' with no type
graph.h:81: parse error before `*'
Why is class GEdge not accepting "NODE"?
Chris 5 4792
"Christian Christmann" <pl*****@yahoo. de> wrote in message
news:3a******** *****@individua l.net... Hi,
I want to implement an graph using templates. In my header file I define the templates node and edge:
template <class NODE> class GNode { NODE *info; public: GraphNode(); void SetInfo(const NODE &x); };
template <class EDGE> class GEdge
Did you mean:
template <class EDGE, class NODE> class GEdge
{ EDGE *info; GNode<NODE> *source; // line 75 GNode<NODE> *target; // line 78 public: GEdge<EDGE>(GNo de* newsource, GNode* newtarget); //line 81
and:
GEdge(GNode<NOD E>* newsource, GNode<NODE>* newtarget);
[snip]
File graph.cpp: [snip] template <class EDGE> GEdge<EDGE>::GE dge(GNode* newsource, GNode* newtarget)
template <class EDGE, class NODE>
GEdge<EDGE,NODE >::GEdge(GNode< NODE>* newsource, GNode<NODE>* newtarget)
: info( NULL )
, source( newsource )
, target( newtarget )
{}
{ src = newsource; trg = newtarget; info = NULL; } [snip]
But the compiler complains: graph.h:75: type/value mismatch at argument 1 in template parameter list for `template <class NODE> GNode<NODE>' graph.h:75: expected a type, got `NODE' graph.h:75: ANSI C++ forbids declaration `source' with no type graph.h:78: type/value mismatch at argument 1 in template parameter list for `template <class NODE> GNode<NODE>' graph.h:78: expected a type, got `NODE' graph.h:78: ANSI C++ forbids declaration `target' with no type graph.h:81: parse error before `*'
Why is class GEdge not accepting "NODE"?
See above.
Also you'll need to think further about which files the member function
definitions appear in, and how they are included, or you'll need to
explicitly instantiate your classes.
Jeff Flinn
Christian Christmann wrote: I want to implement an graph using templates.
Is this for exercise sake? I am asking because there are already
libraries for that. Templates, too.
In my header file I define the templates node and edge:
template <class NODE> class GNode { NODE *info; public: GraphNode(); void SetInfo(const NODE &x); };
template <class EDGE> class GEdge { EDGE *info; GNode<NODE> *source; // line 75
'NODE' is undefined here. What is 'NODE'? Did you mean to add another
template argument to 'GEdge'?
GNode<NODE> *target; // line 78 public: GEdge<EDGE>(GNo de* newsource, GNode* newtarget); //line 81 [snip]
File graph.cpp: [snip] template <class EDGE> GEdge<EDGE>::GE dge(GNode* newsource, GNode* newtarget) { src = newsource; trg = newtarget; info = NULL; } [snip]
But the compiler complains: graph.h:75: type/value mismatch at argument 1 in template parameter list for `template <class NODE> GNode<NODE>' graph.h:75: expected a type, got `NODE' graph.h:75: ANSI C++ forbids declaration `source' with no type graph.h:78: type/value mismatch at argument 1 in template parameter list for `template <class NODE> GNode<NODE>' graph.h:78: expected a type, got `NODE' graph.h:78: ANSI C++ forbids declaration `target' with no type graph.h:81: parse error before `*'
Why is class GEdge not accepting "NODE"?
Because there is no such thing as 'NODE' in the scope of 'GEdge'. The
one existing in the 'GNode' template is limited to the scope of 'GNode'
template class definition (and it would mean nothing outside of it,
anyway).
Let me give you a simpler example
template<class T> class OneTemplate { T data; };
template<class T> class AnotherTemplate { T value; };
In these templates each 'T' means a completely different thing. If I
instantiate
OneTemplate<dou ble> otd;
and then
AnotherTemplate <int> ati;
, the 'T' in 'OneTemplate' instantiation will be 'double' and in the
'AnotherTemplat e' instantiation will be 'int'.
Get yourself a book on C++ and study the templates. This is very basic
stuff to seek assistance of a newsgroup for.
V GEdge(GNode<NOD E>* newsource, GNode<NODE>* newtarget);
Thank you. By the way is the position of '*' important?
I mean, are both statements equal?
GEdge(GNode<NOD E>* newsource, GNode<NODE>* newtarget);
GEdge(GNode<NOD E> *newsource, GNode<NODE> *newtarget);
~~ ~~
Chris I want to implement an graph using templates. Is this for exercise sake?
Yes, it is. I'm new to C++ and need some practice.
I am asking because there are already libraries for that. Templates, too.
Thank you. I'm going to take a look at them.
V
Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Daan |
last post by:
Hello all,
I'm having a little problem with Smarty. Getting it to work in a simple
case went fine, but now I have the following situation:
/
/smarty
/templates
template.tpl
/templates_c
|
by: Buchleitner Martin |
last post by:
Hi!
I got another problem parsing my XML document:
<document>
<paragraph>
<style val=listing/>
<text>listing #1 text</text>
</paragraph>
<paragraph>
|
by: Alan Krueger |
last post by:
Greetings,
I've been able to cache Transformer objects in a Tomcat-based servlet
application to avoid unnecessary Transformer rebuilding, except for
certain ones on certain machines. I'm running Tomcat 4.1.27 under
Eclipse 2.1.0 using the Sysdeo Tomcat plugin using j2re1.4.1_02 under
Windows 2000 SP4.
I've digested this down to a small (albeit convoluted) sample that
exhibits the behavior reliably on my development workstation.
|
by: bjam |
last post by:
Help! The apply-templates function is not currently allowing me to
select a specific template... eventhough I tried putting a select
statement, it does not seem to work??? Can someone help show how I can
select the first template and then have it select others? Below is a
sample of the xml as well as the .xsl file when
I do something like the following in the main section it does not seem
to work, it only works when I remove the select...
|
by: Fred H |
last post by:
I'm currently trying to write a function template that
can fill a variable of arbitrary type with 'random' stuff,
but I can't seem to get my function template working.
In my .h file I've declared the function template like this,
inside a class I'm building:
template <typename T> T RandBits();
In my .cpp file I've implemented it like this:
| |
by: Rob Ratcliff |
last post by:
I'm compiling the latest version of a CORBA ORB called MICO on a Cray
X1. It makes heavy use of templates and namespaces.
Up until the link step, the C++ source code compiled flawlessly. But,
when it tried to link, I got the attached warnings and then an error.
Any ideas why the linker wouldn't see the objects in the library? They
look like pretty long names,
so maybe there is some type of symbol length or mangling issue going
on? The...
|
by: Ali Sahin |
last post by:
Hi there,
I'd like to transform a XML-File to PDF.
The XML-File ist build like followed:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<?xml-stylesheet type="text/xsl"
href="D:\app\jboss-3.2.5\server\default\deploy\xifs.war\WEB-INF\classes\de\xifs\resource\xml\de\xifs\resource\xml\dunningaccountreport_de.xsl"?>
<!DOCTYPE entities >
|
by: david |
last post by:
Hello, I decided to play a bit with templates and classes, but
discovered some problems.
So, I have 3 files: LinkedList.h LinkedList.cpp and test.cpp (by the
way it is not finished fully)
LinkedList.h
#ifndef LinkedList_byDavid
#define LinkedList_byDavid
|
by: Tim Frink |
last post by:
Hi,
I want to use a callback function together with
templates. Let's say I've this code:
File a.h:
class A
{
private:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |