can't use extern with map?

J

JH Programmer

Hi all, I've got a problem when I want to create a global map
//file operator.cpp #include <map> map<string, Staff*>
Symbol_definition; Symbol_definition["+"] = NULL;
Symbol_definition["-"] = NULL; Symbol_definition["*"] = NULL;
Symbol_definition["/"] = NULL;
///////////////////////////////////////////////////////////////////
//file calculate.cpp #include "opertor.cpp" #include <map> extern
map<string, Cell*> Symbol_definition; .... and when I compile it in
g++ then I got the following error operator.cpp:17: error: expected
constructor, destructor, or type conversion before '=' token
operator.cpp:17: error: expected `,' or `;' before '=' token ....same
the others. What cause the error? Thanks
 
V

Victor Bazarov

JH said:
Hi all, I've got a problem when I want to create a global map

I have to reformat the following (what did you use to post it?)
//file operator.cpp
#include <map>
map<string, Staff*> Symbol_definition;
Symbol_definition["+"] = NULL;
Symbol_definition["-"] = NULL;
Symbol_definition["*"] = NULL;
Symbol_definition["/"] = NULL;

The preceding four statements are _executable_ statements (assignments)
and cannot appear by themselves in the global scope. You can make them
part of some bogus (dummy) initialisation. Otherwise, they have to be
part of a function.
///////////////////////////////////////////////////////////////////
//file calculate.cpp #include "opertor.cpp" #include <map> extern
map<string, Cell*> Symbol_definition; .... and when I compile it in
g++ then I got the following error operator.cpp:17: error: expected
constructor, destructor, or type conversion before '=' token
operator.cpp:17: error: expected `,' or `;' before '=' token ....same
the others. What cause the error? Thanks

AFAICT, the existence of executable statements in the global scope.

You'd get the same for this simple program:

int a[2];
a[0] = 42; // executable statement in global scope!
a[1] = 43; // same problem

int main() {
return 0;
}

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top