Ok, reformulated and consolidated from C++ Process terminated with status 3 confusion to a single file with minimum code, replacing my 'log' references with 'cout', printing to console instead of to file. I ran it through code::blocks compiler and got a different error, but for the same line ['log' was not declared in this scope]. It just closes the program with 'status 3' when I have the classes in their own files.
I've run into the scope error before, fixed it on my own, and thought I understood it, but I guess not...
#include <iostream>
#include <string> // Doesn't complain if this is not present...
using namespace std;
//------------------------------------------------------------
class Logfile {
public:
bool LACT; // Is log file active?
string value; // Data to be entered
Logfile();
~Logfile();
void entry(string value); // Make an entry
};
Logfile::Logfile() { // Constructor
LACT = true;
cout << "OPENED\n";
}
Logfile::~Logfile() {
cout << "CLOSED\n";
}
void Logfile::entry(string value) {
if ( LACT ) cout << value << endl;
}
//--------------------------------------------------
class Engine { // Constructor contains only code for this class right now
public :
Engine();
};
This line is where the compiler hangs and gives me the error:
Engine::Engine() {
log.entry("Engine constructed"); // !Problem line!
}
Am I on the right track thinking that the problem is that I am incorrectly calling a class method of an existing object from within a different class?
//--------------------------------------------------
int main()
{
Logfile log;
Engine engine;
cout << "Hello world!" << endl;
return 0;
}
When I '//' the line in question, everything runs fine and the console prints up the OPENED, Hello World!, CLOSED. Thank you for your patience and time, as I'm sure this is something far simpler - and novice - than it appears to be to me.
--
My initial purpose for asking this question was (now I realize) to get a globally declared object accessible from any *.cpp file in a multi-file program. I just found this answer: http://www.cplusplus.com/forum/beginner/3848/, in case this might be helpful to anyone else with a similar problem.