Link to home
Start Free TrialLog in
Avatar of EmailSurfer
EmailSurfer

asked on

Compiler namespace error?

Hello,

Could anyone advise? I have an example code which includes a namespace jminus. But when I try to reference the code inside the namespace from a separate file main.cpp many errors are displayed including :

std::auto_ptr< jminus::abstract_interpreter > 
jminus' has not been declared

I posted the code at http://members.aol.com/emailsurfer95/ and wondered if the code could not be posted. It was a friends example and I am not sure if they would like it posted.

Many thanks
Avatar of arun_vip
arun_vip

Hi,
This might be because of two reasons.
1. Include the jminus header.
a. The compiler couldn't locate this namespace while compiling your code.

2. Can you try with using namespace.
Can you try your code with
using namespace jminus;
You are getting namespace error, then the location of the namespace couldn't find.
ASKER CERTIFIED SOLUTION
Avatar of B1-66ER
B1-66ER

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of EmailSurfer

ASKER

Thank you for replying.

In my friends version, they declared the #include statements in the main.cpp and some of the .hpp files as:

#include "jminus/some.hpp"

Could anyone advise if the jminus used in the #include statements means the files hpp files should be placed in a folder named jminus and the main.cpp outside this folder?

I posted the new verions at:

http://members.aol.com/emailsurfer95/

I would much appreciate if anyone could try and compile the main.cpp to see if you also recieve the many errors?

thank you
>> Could anyone advise if the jminus used in the #include statements means the files hpp files should be placed in a folder named jminus and the main.cpp outside this folder?

yes

>>I would much appreciate if anyone could try and compile the main.cpp to see if you also recieve the many errors?

i cant try to compile because in file 'statement.hpp' there is no any decaration of 'statement', its size == 0.
Thanks

I created a folder c++, then created a second folder inside called jminus where I placed all the .hpp files. I placed the main.cpp file in the c++ folder.

When I compiled the main.cpp file, I got the error:

jminus' has not been declared

pointing to the line std::auto_ptr< jminus::abstract_interpreter > 

This was the same error as before.
>> I created a folder c++, then created a second folder inside called jminus where I placed all the .hpp files. I placed the main.cpp file in the c++ folder.

did you include in main.cpp header file in which defined namespace 'jminus' 7

#include "jminus/HEADER_WHERE_JMINUS_NM_DEFINED.hpp"
Does this code point tot he jminus namespace?

std::auto_ptr< jminus::abstract_interpreter >

To remove the compiler error:

jminus' has not been declared

error pointing to the line std::auto_ptr< jminus::abstract_interpreter >

Should I include the #include in main.cpp

#include "jminus/abstract_interpreter.hpp"

abstract_interpreter.hpp is where the jminus namespace is declared.

Thank you
>>Should I include the #include in main.cpp
#include "jminus/abstract_interpreter.hpp"
abstract_interpreter.hpp is where the jminus namespace is declared.

YYYYES! :))
to have access to some namespace you must include header where this namespace declared.
Thank you,

Many of the errors have now passed.

Could I ask finally before closing the question. The cpp file includes an exception in the main here is the catch:

catch( jminus::interpreter_exception& e )
{
std::cerr << "Interpreter exception: [" << e.what() << "] reading script " << argv[ file_number ] << std::endl;
result = EXIT_FAILURE;
}

In this catch, will I need to write my own exception. And could you possibly advise how to start this?

Many thanks