a list as a member variable

let say, I want to make a c++that will allow me to read the content of a file that I will call file.txt
I will create:
1- ReadDocument.h (that contains my class)
2- ReadDocument.cpp (That will contain my functions)
3- UseDocument.cpp (That will contain my main function, and will allow me to access all the others)

I don't want to open the file, and copy the content in a list every time I access a function.

Where should I create my list that contains the words from the file i opened? and how does the list pass through all the files as a member variable?
After you create your list, you can pass it around to other functions using references. For instance,

function delclaration:
size_t processList(std::list<int>& myList);

function definition:
1
2
3
4
size_t processList(std::list<int>& myList)
{
    return myList.size();
}


Function call:
1
2
3
4
std::list<int> myList;
myList.push_back(1);
myList.push_back(10);
std::cout << "Size of list: " << processList(myList) << std::endl;


You can pass a reference to an empty list to a function and have the function read the file and populate the list. You can then pass a reference to the list to another function and have the other function manipulate the list. When the functions return, the original list will have been modified by the called function.
Thank you for he answer.

But where should i create open the file and affect its elements to "myList".
in Which file is it better to create it ??

ReadDocument.h , ReadDocument.cpp or UseDocument.cpp ?
Which one is more effective, professional and more interesting to do it?
I think you'd be better off looking at something like this to get some general background first re what goes where:

http://stackoverflow.com/questions/1945846/what-should-go-into-an-h-file

To answer your specific question, myList should go into UseDocument.cpp

Also, I want to seek clarification on something you mention in your original post:

that will allow me to read the content of a file that I will call file.txt ... and how does the list pass through all the files as a member variable


- are you planning to work with just the one file or multiple files, one after the other?
Yes, i am planning to work with only one file.

i was planning to put the content of the file in a list and pass that list through all the functions that have to deal with the content.
Topic archived. No new replies allowed.