Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > can't use extern with map?

Reply
Thread Tools

can't use extern with map?

 
 
JH Programmer
Guest
Posts: n/a
 
      05-17-2006
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

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      05-17-2006
JH Programmer wrote:
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference of extern short *x and extern short x[]? Andre C Programming 5 07-17-2012 07:38 PM
confused about extern use Lalatendu Das C Programming 9 02-22-2007 04:19 AM
Use of 'extern' keyword siliconwafer C Programming 5 07-31-2005 03:39 AM
how to use the keyword extern in c? ooze C Programming 16 08-30-2004 04:39 PM
extern const char * vs. extern const char []http://tinyurl.com/47e3k Thomas Matthews C++ 5 08-02-2004 10:36 AM



Advertisments
 



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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57