473,804 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STL <list> declaration in header file

Hi there!

I'm just trying to compile a header file (unsing Borland C++ Builder
10)implementing a class, containing the declaration of the STL <list>
but it
refuses to work.

The following errors occure:
"test.h" line 29 type name expected
"test.h" line 29 declaration missing

Interesting is that it works if I copy the declaration into the
main.cpp
file!

Here is the source:

<snip fileName="test. h">
class xy
{
public:
void getI(void);
void setI(int);

private:
int i;
};

class xyy
{
public:
void do_something(vo id);

private:
list <xy *> myList;
};
</snip>
Thanks in Advance!
Günter
Jul 22 '05 #1
5 8711
G?nter Omer wrote:
Hi there!

I'm just trying to compile a header file (unsing Borland C++ Builder
10)implementing a class, containing the declaration of the STL <list>
but it refuses to work.
Header files aren't supposed to be compiled separately.
The following errors occure:
"test.h" line 29 type name expected
"test.h" line 29 declaration missing

Which line is line 29?
Interesting is that it works if I copy the declaration into the
main.cpp file!
What main.cpp file? Your example doesn't show that file. Without
context, there is nothing wrong with that header file, though I'd
recommend making headers self contained, i.e. add every #include the
header needs. So I'd add:

#include <list>

at the top and replace

list <xy *> myList;

with

std::list <xy *> myList;
Here is the source:

<snip fileName="test. h">
class xy
{
public:
void getI(void);
void setI(int);

private:
int i;
};

class xyy
{
public:
void do_something(vo id);

private:
list <xy *> myList;
};
</snip>


Jul 22 '05 #2
Thanks for your fast answer and excuse my uncomplete post!

Here are all three files of the testing program, line
29 is marked:

test.h
----
/*

*/
#ifndef TEST_HEADER
#define TEST_HEADER

class xy
{
public:
void getI(void);
void setI(int);

private:
int i;
};

class xyy
{
public:
void do_something(vo id);

private:
list <xy *> myList; // -> this is line 29!
};

#endif
----
/*

*/

#include <iostream>
#include "test.h"
using namespace std;

int main(int argc, char *argv[])
{

return 1;
}

----

test.cpp
----
/*

*/

#include <iostream>
#include <list>
#include "test.h"

using namespace std;

void xy::getI(void)
{
cout << i << endl;
}

void xy::setI(int iIN)
{
i = iIN;
}
void xyy::do_somethi ng(void)
{
xy *xytemp;
xy *myXY = new xy;
myList.push_fro nt(myXY);

list <xy *>::iterator myIterator;
myIterator = myList.begin();

xytemp = *myIterator;
delete myXY;

}

void xyy::output(voi d)
{
myIterator = myList.begin();
xy *myXY = *myIterator;
cout << myXY->getI() << endl;
myList.pop_back ();

}
/**/

----

Tanks!
-Günter
Jul 22 '05 #3

"G?nter Omer" <gu*****@omer.a t> wrote in message
news:50******** *************** ***@posting.goo gle.com...
Thanks for your fast answer and excuse my uncomplete post!

Here are all three files of the testing program, line
29 is marked:

test.h
----
/*

*/
#ifndef TEST_HEADER
#define TEST_HEADER

class xy
{
public:
void getI(void);
void setI(int);

private:
int i;
};

class xyy
{
public:
void do_something(vo id);

private:
list <xy *> myList; // -> this is line 29!
};

#endif
----
/*

*/

#include <iostream>
#include "test.h"
using namespace std;

int main(int argc, char *argv[])
{

return 1;
}

----

test.cpp
----
/*

*/

#include <iostream>
#include <list>
#include "test.h"

using namespace std;

void xy::getI(void)
{
cout << i << endl;
}

void xy::setI(int iIN)
{
i = iIN;
}
void xyy::do_somethi ng(void)
{
xy *xytemp;
xy *myXY = new xy;
myList.push_fro nt(myXY);

list <xy *>::iterator myIterator;
myIterator = myList.begin();

xytemp = *myIterator;
delete myXY;

}

void xyy::output(voi d)
{
myIterator = myList.begin();
xy *myXY = *myIterator;
cout << myXY->getI() << endl;
myList.pop_back ();

}
/**/

----

Tanks!
-Günter


You should add the lines:

#include <list>
using namespace std;

to test.h so that the compiler will know what you mean by 'list'.

You could get away with having these two lines in the source file *before*
including test.h but then you would need them in every source file that
includes test.h which would be ugly, messy and bad.

Tom
Jul 22 '05 #4

"Thomas Wintschel" <th******@telus .net> skrev i en meddelelse
news:c4Fvb.1189 75$jy.61847@clg rps13...

"G?nter Omer" <gu*****@omer.a t> wrote in message
news:50******** *************** ***@posting.goo gle.com...
Thanks for your fast answer and excuse my uncomplete post!

Here are all three files of the testing program, line
29 is marked:

test.h
----
/*

*/
#ifndef TEST_HEADER
#define TEST_HEADER

class xy
{
public:
void getI(void);
void setI(int);

private:
int i;
};

class xyy
{
public:
void do_something(vo id);

private:
list <xy *> myList; // -> this is line 29!
};

#endif
----
/*

*/

#include <iostream>
#include "test.h"
using namespace std;

int main(int argc, char *argv[])
{

return 1;
}

----

test.cpp
----
/*

*/

#include <iostream>
#include <list>
#include "test.h"

using namespace std;

void xy::getI(void)
{
cout << i << endl;
}

void xy::setI(int iIN)
{
i = iIN;
}
void xyy::do_somethi ng(void)
{
xy *xytemp;
xy *myXY = new xy;
myList.push_fro nt(myXY);

list <xy *>::iterator myIterator;
myIterator = myList.begin();

xytemp = *myIterator;
delete myXY;

}

void xyy::output(voi d)
{
myIterator = myList.begin();
xy *myXY = *myIterator;
cout << myXY->getI() << endl;
myList.pop_back ();

}
/**/

----

Tanks!
-Günter


You should add the lines:

#include <list>
using namespace std;

to test.h so that the compiler will know what you mean by 'list'.

You could get away with having these two lines in the source file *before*
including test.h but then you would need them in every source file that
includes test.h which would be ugly, messy and bad.

Tom

Never put a using directive in a header-file. This is a potential source of
problems.

Kind regards
Peter Koch Larsen
Jul 22 '05 #5
Thomas Wintschel wrote:
You should add the lines:

#include <list>
using namespace std;

to test.h so that the compiler will know what you mean by 'list'.


You should just add
#include <list>

Then use std::list.

Don't put 'using' in a header.

--
Unforgiven

"Most people make generalisations "
Freek de Jonge
Jul 22 '05 #6

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

Similar topics

4
1300
by: lallous | last post by:
Hello Given this: list<mystruct_t> lst; lst.push_back(item1); lst.push_back(item2); lst.push_back(item3);
5
6257
by: Kenneth | last post by:
<list> seems to be a powerful structure to store the related nodes in memory for fast operations, but the examples I found are all related to primitive type storage. I'm doing a project on C++ with my defined classes to be added to linked list structure so as to facilitate the operation of all instances of defined classes. Is that possible to apply such classes to <list> or <Vector> structure? Thanks!
2
2070
by: Tom Vogel | last post by:
I'd like to use the XML Documentation Tags to comment my C# code. But many of the tags do not have any effect when I execute the "Build Comment Web Pages" menu. For example, the <list> tag gets reendered as is. The resulting HTML page contains the exact same tags, which are not valid HTML. The same with <see> or <see also>. Isn't this function supposed to transform these tags into valid HTML? Did anybody see this work properly?
1
1434
by: Steffo | last post by:
Why can't I use stl list in my dll. I'ts no problem with vector, but when trying list I get the followning error msg: error C2061: syntax error : identifier 'list' Hu!! S.
3
2239
by: kuiyuli | last post by:
I'm using VC++ .Net to do a simlple program. I tried to use <vector> <list> in the program, and I simply put the folowing lines " #include <list> #include <vector> #include <string> using namespace std; ...... vector <Vector> vectorlist;
17
2105
by: Cralis | last post by:
I am trying to populate a ListView with a list of 'Models' of cars. I have a data object class for my models, which has a function, 'getListOfModels', which I want to retuyrn a <Listof models. In my data object, I have also created a class to hold each model, as shown below. No database work has been done. Just adding a model, and trying to return it.
12
2653
by: arnuld | last post by:
It works fine. any advice on making it better or if I can improve my C++ coding skills: /* C++ Primer - 4/e * * Chapter 9 - Sequential Containers * exercise 9.18 - STATEMENT * Write a program to copy elements from a list of "ints" * to 2 "deques". The list elements that are even should go into one deque * and even elements should go into 2nd deque.
0
9712
marktang
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...
0
9594
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,...
0
10343
jinu1996
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...
0
10089
tracyyun
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...
0
9171
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6862
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();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
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
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.