Compile error: 'identifier' : already initialized

M

Marc W

Hello,

I am trying to write some code, I get a compiler error, but the help about
it is very limited. (I am working with MSVC++ 6.0.) Could you give me a hint
what is wrong here please?

MyImpl.h(11) : error C2437: 'OBV_Example' : already initialized

Compiler Error C2437
'identifier' : already initialized
The specified identifier was already initialized.
An object can be declared more than once but can be initialized only once.

class ExampleImpl : public virtual Sample::OBV_Example,
public virtual CORBA::DefaultValueRefCountBase
{
public:
ExampleImpl(){}
ExampleImpl(CORBA::Long aLong) //this is line 11
: Sample::OBV_Example(aLong) {}
virtual ~ExampleImpl(){cout << "Example destructor has been caaLonged. MyVal
CORBA_ValueBase* _copy_value() {return new ExampleImpl(l());}

};
 
I

Ivan Vecerina

| I am trying to write some code, I get a compiler error, but the help about
| it is very limited. (I am working with MSVC++ 6.0.) Could you give me a
hint
| what is wrong here please?
Your code is ok according to the C++ standard (provided all types&base
classes were defined appropriately).

| MyImpl.h(11) : error C2437: 'OBV_Example' : already initialized

Your compiler seems to have a problem with the explicit initialization
of a virtual base class -- which is perfectly legal according to the
standard (12.6/1 and /6), but requires some special handling.
(only the most-derived constructor will initialize the virtual
base classes, other initialization expressions are ignored).

The only workarounds I can imagine are:
- use a non-virtual base class, or rely on the virtual base class
defined in another base class (e.g. OBV_Example).
- remove the constructor that creates the problem
(the one with an explicit initial reference count)
- use another compiler...

I hope one of these options can do...
Ivan
 
M

Marc W

Ivan Vecerina said:
- use another compiler...

Hello thanks, and it compiles on HPUX etc. May-be somebody knows a compiler
option for MSVC6.0 that fixes this?
 
I

Ivan Vecerina

Hi Marc,
|
|
| > - use another compiler...
|
| Hello thanks, and it compiles on HPUX etc. May-be somebody knows a
compiler
| option for MSVC6.0 that fixes this?

This problem is not an extension/option, but a limitation of the compiler.
If the problem persists with the latest service pack for MSVC6 (SP5 IIRC)
and you have installed it already, I don't think there is much you can do.
To compile this valid code as is, you can:
- upgrade to MSVC7.x, which does not have this limitation.
- switch to intel's C++ compiler -- its GUI-based installer
allows it to run within MSVC6, and will not have this problem either.
- switch to another compiler that is more standards compliant.

Or, as I had suggested, change your code to work around the limitation:
- use a non-virtual base class, or rely on the virtual base class
defined in another base class (e.g. OBV_Example).
- remove the constructor that creates the problem
(the one with an explicit initial reference count)

If in doubt, you can also ask for suggestions in the Corba community
(this problem must have been faced by others before), or in a
forum dedicated to MSVC.

All you should expect from this NG is:
- a confirmation that your code is valid C++
- suggestions to make your code more compatible with older compilers
.... which I did in my previous post.


Good luck,
 

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,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top