OK. I've seen several posts on the subject in
the archives, but I still seem to be stuck.
Perhaps someone with fresher, more knowledgeable
eyes can tell me what I'm doing wrong?
I'm getting the error:
mapinit.cpp:15: error: expected initializer before 'A'
when I try to compile the following, and for the
life of me I can't figure out WHY. Anyone?
(I've tried several variations of this, including
declaring _init_mapconst() as const, and not using
inline, etc. Same error each time.)
Any assistance welcome.
thanks,
Marc
// minimal example of map initialization problem:
#include <string>
#include <map>
class A {
private:
typedef std::map<std::string, intmaptype_t;
static const maptype_t _mapconst;
static maptype_t _init_mapconst();
}
inline A::maptype_t
A::_init_mapconst() // line 15
{
maptype_t m;
m["aaa"] = 23;
m["acb"] = 42;
return m;
}
const A::maptype_t
A::_mapconst =
A::_init_mapconst();
int main()
{
}
/* compilation attempt:
$$g++ -Wall -pedantic -ansi mapinit.cpp -o mapinit
mapinit.cpp:15: error: expected initializer before 'A'
$$g++ --version
g++ (GCC) 4.0.2
*/
--
Marc D.
(note that reply-to is a black hole.]
Use list [at] ryuu in Canada to send email.
Or, preferably, reply here... 2 8894
Marc D wrote:
OK. I've seen several posts on the subject in
the archives, but I still seem to be stuck.
Perhaps someone with fresher, more knowledgeable
eyes can tell me what I'm doing wrong?
I'm getting the error:
mapinit.cpp:15: error: expected initializer before 'A'
when I try to compile the following, and for the
life of me I can't figure out WHY. Anyone?
(I've tried several variations of this, including
declaring _init_mapconst() as const, and not using
inline, etc. Same error each time.)
class A {
private:
typedef std::map<std::string, intmaptype_t;
static const maptype_t _mapconst;
static maptype_t _init_mapconst();
}
Missing semicolon!
--
Ian Collins.
Ian Collins wrote:
Marc D wrote:
[...]
>}
Missing semicolon!
::beats head against large brick wall::
Thanks for that! You have no idea how long I've
looked at the original problem, and this reduced
set...
need sleep.
--
Marc D. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steven T. Hatton |
last post by:
Is there a way to initialize an member array of user defined objects that is
declared static const?
For example:
const vec3f I(1,0,0);
const vec3f j(0,1,0);
class corner_functor
{
|
by: trying_to_learn |
last post by:
I'm learning consts in C++ and the book says that u have to initialize
non-static consts inside the constructor initializer list, however
"const string* stack" isn't initialized in the constructor...
|
by: Drew McCormack |
last post by:
I am getting an error in g++ 4.0.0 that I did not get in g++ 3.4. I
have a header with the following const variables with namespace scope:
namespace Periphery {
extern const double...
|
by: Bart Goeman |
last post by:
Hi,
I have a question about how to put redundant information in data
structures, initialized at compile time. This is often necessary
for performance reasons and can't be done at run time (data...
|
by: Daniel Switkin |
last post by:
Hi there,
I'm trying to do the following:
class tLimits {
static const int kIntMin = 0; // fine
static const float kFloatMin = 0.0f; // breaks
};
and I get this message:
|
by: Diebels |
last post by:
Hi,
I have some problems using static variables which results in a core
dump. I have attached code and coredump to the end of my message.
I am trying to implement a kind of factory design. I...
|
by: utab |
last post by:
Dear all, I am confused at some point on the initialization of static
map member of a class. The class I have designed id something like
this.
class Class_name{
public:
private:
|
by: newsposter0123 |
last post by:
The code block below initialized a r/w variable (usually .bss) to the
value of pi. One, of many, problem is any linked compilation unit may
change the global variable. Adjusting
// rodata
const...
|
by: sunil |
last post by:
Hello,
I am new to c# . I have some basic programming doubts. Please help me
in clarifying these doubts.
I want to initialize a static and readonly field with a value returned
by a static...
|
by: david.baird |
last post by:
I have 3 classes, 1 which does not use templates, CGood, and 2 which
do use templates, CBad, and COkay. I believe that all of them should
work, but only CGood and COkay are working for me. CBad...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |