VS 2005 and Standard Template Library List where? (please)

Associate
Joined
4 Jun 2003
Posts
770
Location
United Kingdom
I have setup a standard windows c++ project, and I want to use a list.

My question is, where do I put the "#include <list>"?

After that is sorted, where can I declare a list e.g. "list <int> c0"?

I want to access the list as a result from the button press.

Thanks

P.S. Perhaps I'm going about this the wrong way? But it would be the easiest way to accomplish this simple task.
 
Just to be clear

Where do I put the #include - which file? (Form.h, project.cpp etc)

Where do I declare a list so that the entire programcan access it?

Thanks
 
You put it at the top of your header file.

You could declare your list as a global (very bad practice).. Your best to encapsulate it in a class though.
 
Last edited:
if project.cpp has a header file, put it at the top of that, otherwise just stick it at the top of project.cpp

JD
 
For good programming practice, where should I declare a list instance?

#include still at the top of project.cpp I presume?
 
I want to access the list when a couple of buttons are pressed.

Should I create my own class, declare the list there and simply call class functions from the button presses?
 
Sorry to be negative, or if it sounds like im insulting you, but do you actually know what your doing? In which case i'd say your getting too far ahead of yourself.

It's just your asking a lot of very basic questions
 
Welshy said:
Sorry to be negative, or if it sounds like im insulting you, but do you actually know what your doing? In which case i'd say your getting too far ahead of yourself.

It's just your asking a lot of very basic questions

I know what I'm doing for the most part thanks, I'm a bit rusty on good C++ programming practice though. It has been quite some time since I programmed, I'm new to VS 2005 and never used the STL before.

Fancy answering my question on whether it would be a good idea to include the list in my own class (which will have other things in also) and access it through my own functions?
 
Minority said:
I know what I'm doing for the most part thanks, I'm a bit rusty on good C++ programming practice though. It has been quite some time since I programmed, I'm new to VS 2005 and never used the STL before.

Fancy answering my question on whether it would be a good idea to include the list in my own class (which will have other things in also) and access it through my own functions?
Oh ok, fair enough mate :)

It would completely depend on what goal you were trying to achieve. You could make your own list class by inheriting from it, and add your own functions etc, or just create an instance of the ready made list and use the functions already associated with it.


Going back to header files, to maintain reusability you'll want to do something like this:

SomeClass.h (class data, function headers, constructors etc)
Code:
class SomeClass
{
    public:
        
    private:
};

SomeClass.cpp (implementation of functions etc)
Code:
#include "SomeClass.h"

SomeClass::SomeClass()
{
}

SomeClass::~SomeClass()
{
}

Main.cpp
Code:
#include <iostream.h>
#include "SomeClass.h" // dont include the .cpp file(s), the linker will do the work for you

int main()
{
    // insert code here
}

You should be able to use the List class in any file that you've included the header file at the top.

Hope that helps, and isnt too long winded :o

P.S. this has helped me a lot when learning/brushing up on C/C++
 
Last edited:
Something I'm not clear on is where I would create an instance of my own class so that I can access the class functions from multiple parts of the program.

I have Form1, which has a section for code when Button1 is pressed and another section for when Button2 is pressed.

How do I create in instance so that these two seperate buttons can access this?

This is probably a very stupid question, in fact, I know it is. I just can't remember.

edit

To be clear, this is a VS2005 created Win32 app, so it has created the sections for button presses. I believe it does this in the form of a class.

edit2

Not to worry. Got it sorted. I think I'm back on track now.
 
Last edited:
Back
Top Bottom