I'm not entirely sure that you and I are using "header" with the same meaning, but there is no such restriction. Any function can open and read files. For example, your main() could look like this: |
I'm sorry my phrasing of the question was very poor.
I wanted to do these calls in a header file:
1 2 3 4 5
|
YourClass o("file.txt");
extern o;
|
And then these
1 2 3
|
void o.analyze;
//prints data analyssi to command prompt
|
in main.
This is really stupid. I think I know why. I another thread someone told me I should store my data in separate files. I thought he meant in separate C++ files. So I asked:
First, how do I access objects I've defined in one source file in another? |
STUUPPID!
I meant objects I've CONSTRUCTED, not DEFINED.
a constructor is a function. YOu can't make function calls in header files! Header files are only fore forward declarations. Instead, I should have understood that My data will always be stored in a text file, and when I construct objects using this data in main, space is allocated for it using the constructor. When I'm done analyzing it and printint the resultsi, I use the destructor, and my data stays safe in the original text file. As long as I only ever READ data using ffstream, and not ifstream (or whatever class reads and writes text files) I won't ever mess it up.
This is what they were trying ot tell me in another thread.
One more Quick question: if I have a lot of data, is it better to allocate space on the stack or the heap for this class? Each instance of this class will have text fils worth of data in, and I could have a bunch of them constructed in main for analysis.
Thanks for the help guys! I really like forums because sometimes we get these sort of stupid ideas in your heads about how things are supposed to work. Talking it out helps, especially when I get strange replies from everyone.
Never learn anything in a vacuum!
-Trent