473,325 Members | 2,785 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,325 software developers and data experts.

lists in a class

Kev
Is using a list in a class unusual? All the examples I find searching
through lots of web pages and books all show them in main.

What Im doing: Main does initialization of the screen and things like that.
Then the program is passed to a single instance of a class that controls
everything from there, and doesnt return to main until the program ends. Im
looking to use a few lists (list<int> myint) in it. First idea was to put
them in the contructor... which didnt work as other functions outside of it
didnt them. No surprise. Put the lines in the header or putting them
outside the class itself? Nope... errors like "pushback is not a member
function".

I did read in a few places that the SGI's STL conflicts with the MS one
included in VC++. Perhaps its that, if one of the above is actually the
right way to go about it.

cheers
Jul 23 '05 #1
7 1237
Kev
Kev <di**************@pht.zzz> wrote in news:Xns9692E4C6A2F32kevsmail@
216.168.3.44:
cheers


Followup. The line is "list<myclass> classlist". And it seems it doesnt
like using 'myclass'. As a test I used 'int' and the test line using it
work.

So... more reading about using objects inside lists ;o)

cheers again
Jul 23 '05 #2
Kev <di**************@pht.zzz> schrieb:
Is using a list in a class unusual?
No.
Im looking to use a few lists (list<int> myint) in it.
What's the problem?
First idea was to put them in the contructor... which didnt work as
other functions outside of it didnt them.
?
Put the lines in the header or putting them outside the class
itself? Nope... errors like "pushback is not a member function".
Well, pushback *is* not a member function.
I did read in a few places that the SGI's STL conflicts with the MS
one included in VC++.


Read something about push_back.

T.M.

class MyClass {
list<int> m_list;
public:
MyClass ()
: m_list()
{
m_list.push_back(1);
m_list.push_back(2);
m_list.push_back(3);
}
};
Jul 23 '05 #3
Kev <di**************@pht.zzz> schrieb:
The line is "list<myclass> classlist". And it seems it doesnt like
using 'myclass'. As a test I used 'int' and the test line using it
work.


Could you please show the code? We are still talking about soap
bubbles.

T.M.
Jul 23 '05 #4
Ian
Kev wrote:
Is using a list in a class unusual? All the examples I find searching
through lots of web pages and books all show them in main.
Why should it be, it's just another container.
What Im doing: Main does initialization of the screen and things like that.
Then the program is passed to a single instance of a class that controls
everything from there, and doesnt return to main until the program ends. Im
looking to use a few lists (list<int> myint) in it. First idea was to put
them in the contructor... which didnt work as other functions outside of it
didnt them. No surprise. Put the lines in the header or putting them
outside the class itself? Nope... errors like "pushback is not a member
function".

Some examples would help! There is no pushback, there is push_back.

Ian
Jul 23 '05 #5
I am not sure that i understand your problem. But the answer of
following is
Is using a list in a class unusual? No. We always do this thing.All the examples I find searching
through lots of web pages and books all show them in main.

In books/web, they show only simple example of using list, therefore
they use them in only main function, it doesn't mean that u can't use
them elsewhere.
In C++, a datatype can be used in any function / class to declare its
variables.

See following simple example,
class A
{
private: ///data member
list<int> myint;
list<float> myfloat;
list<string> mystring;
.....
public:
A(): myint(5) ////five elements, initialized to zero
, myfloat(10,3.25f) ////10 elements, all initialized to
3.25f
{
myfloat.push_front(25.34);
mystring.push_front("jt");
}
void AddData(int _intdata, float _floatdata, string _stringdata)
{
myint.push_back(_intdata);
myfloat.push_back(_floatdata);
mystring.push_back(_stringdata);
}
.................. Define member functions which may operate on your
lists
};

int main()
{
A a,b,c;
///use them as u want
return 0;
}

Jul 23 '05 #6
How u can use list, see here -
http://www.ccd.bnl.gov/bcf/cluster/p...8858.htm#6.2.1
Followup. The line is "list<myclass> classlist". And it seems it doesnt
like using 'myclass'.

How u conculded this? could u like to show that piece of code?

Jul 23 '05 #7
Kev
Ian <no***@nowhere.com> wrote in news:1121320417.836526@drone2-svc-
skyt.qsi.net.nz:
Some examples would help! There is no pushback, there is push_back.

Ian


I truly.... truly.... truly hate it when I do that. And it was staring me
in the face the whole time ;o)

Thanks a bunch
Jul 23 '05 #8

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

Similar topics

5
by: Alan Little | last post by:
I need to merge and de-duplicate some lists, and I have some code which works but doesn't seem particularly elegant. I was wondering if somebody could point me at a cleaner way to do it. Here's...
7
by: Chris Ritchey | last post by:
Hmmm I might scare people away from this one just by the title, or draw people in with a chalange :) I'm writting this program in c++, however I'm using char* instead of the string class, I am...
1
by: Jacek Dziedzic | last post by:
Hi! A) Why isn't it possible to set a member of the BASE class in an initialization list of a DERIVED class constructor (except for 'calling' the base constructor from there, of course)? I even...
2
by: Skywise | last post by:
I am fairly new to linked lists. I am trying to write a class using linked lists. It seems to work fine, but I need to know if I have any resource leaks in it because I plan on using this class...
4
by: Christian Christmann | last post by:
Hi, I've some old code which I would like to replace by STL. It's a self-written double linked list which consists of instances of another class Element which contains the information as void*...
7
by: Christian Christmann | last post by:
Hi, in the past I always appreciated your help and hope that you also can help me this time. I've spent many many hours but still can't solve the problem by myself and you are my last hope. ...
1
by: andrew | last post by:
Hi, I'm a C++ newbie, so apologies for this rather basic question. I've searched for help and, while I understand the problem (that the outer class is not yet defined), I don't understand what...
1
by: Simon Forman | last post by:
I've got a function that I'd like to improve. It takes a list of lists and a "target" element, and it returns the set of the items in the lists that appear either before or after the target...
2
by: Christian Chrismann | last post by:
Hi, an application uses a wrapper class for an STL list. Basically, this template class provides the same functions (delete, append, find...) as an ordinary STL list. Additionally, there are...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.