By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,923 Members | 1,162 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,923 IT Pros & Developers. It's quick & easy.

lists in a class

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.