"error: 'foo' was not declared in this scope", but it is...right here

Main_Log.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <fstream>
#include "Main_Log.hpp"

using namespace std;

namespace OUT {
	bool initiated=false;
	ofstream logfile;
	ifstream checkexist;
	void init() {
		if(checkFileExistance("OUT.log")) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
			logfile.open("OUT.log");	
		}
	}
	void log(string message) {
		cout << "INFO:     " << message << endl;
	}
	void warn(string message) {
		cout << "WARNING:  " << message << endl;
	}
	void crit(string message) {
		cout << "CRITICAL: " << message << endl;
	}
	bool checkFileExistance(string filename) {
		checkexist.open(filename.c_str());
		bool returner = checkexist;
		checkexist.close();
		return returner;
	}
}


Main_Log.hpp
1
2
3
4
5
6
7
8
9
10
11
#ifndef __Main_Log
#define __Main_Log
namespace OUT {
	bool initiated;	//true if its ready, false otherwise
	void init();	//must be called before logging is to occur
	void log(std::string);	//basic out
	void warn(std::string);	//more serious out
	void crit(std::string);	//something that would cause the program to fail if it's not fixed...out
	bool checkFileExistance(std::string);	//true if it does, false otherwise
}
#endif 


I plan to call OUT::init() from another file. I have my calling methods working, but when I attempt to compile this, I get:
Main_Log.cpp: In function ‘void OUT::init()’:
Main_Log.cpp:11:34: error: ‘checkFileExistance’ was not declared in this scope
Last edited on
Main_Log.cpp
1
2
3
4
5
#include "Main_Log.hpp" // **** added
#include <iostream>
#include <fstream>

// ... 
I added that...now I am getting:
Main_Log.cpp:8:7: error: redefinition of ‘bool OUT::initiated’
Main_Log.hpp:4:7: error: ‘bool OUT::initiated’ previously declared here


if I remove the bool on line 7 of Main_Log.cpp, then I get:
Main_Log.cpp:8:2: error: ‘initiated’ does not name a type
Last edited on
Main_Log.hpp
1
2
3
4
namespace OUT {
	extern bool initiated ; // **** declaration (extern)
        // ...
}


Main_Log.cpp
1
2
3
4
5
6
7
#include "Main_Log.hpp" 
// ...

namespace OUT {
	bool initiated=false; // **** definition

        // ...  
Thanks so much, that fixes so many problems. The extern did it for me.
Topic archived. No new replies allowed.