473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

can't use extern with map?

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

May 17 '06 #1
1 3453
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
May 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ik | last post by:
Hello all, Under C++ when 'extern' is used with out the string literal "C" does it act the same as a 'static' ? When is it appropriate using 'extern' ? Thanks ~Ik
111
by: JKop | last post by:
Okay here we go, I feel it's about time people conversed about the bullshit aspects of C++ (including the bullshit stuff brought forward from C). I'll begin with a few of my own grievances: 1)...
12
by: G Patel | last post by:
I've seen some code with extern modifiers in front of variables declared inside blocks. Are these purely definitions (no definition) or are they definitions with static duration but external...
19
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the storage-class specifier will have "extern" as the default...
29
by: DevarajA | last post by:
Can anyone explain me what extern is used for? I thought it was used to declare variables definited in other files, but i can do that also without extern. /*file a.c*/ int a=5; int main() {...
5
by: siliconwafer | last post by:
Hi all, I wanted to know that is use of extern keyword mandatory in case of global variables and functions used in other source files? i.e consider a following piece of code from MSDN explaining...
17
by: Tapeesh | last post by:
I would like to know what is the expected behaviour of C compilers when an extern decleration is intialized. When the following code is compiled using gcc //File extern.c int arr ; int a ;
7
by: MikeF | last post by:
Group, I have a variable declared in 'main.c' as: const unsigned int x = 1; I have another module which uses this same variable, I've tried to declare as:
4
by: nospam_timur | last post by:
Let's say I have two files, myfile.h and myfile.c: myfile.h: int myfunction(int x); myfile.c: #include "myfile.h"
3
by: polas | last post by:
I have a quick question - I have used extern quite a bit in relation to variables, however was wondering if its applicable to function prototypes too? For instance, I have a file called a.c - a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.