Compile error: 'identifier' : already initialized

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc W

    Compile error: 'identifier' : already initialized

    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_Exa mple,
    public virtual CORBA::DefaultV alueRefCountBas e
    {
    public:
    ExampleImpl(){}
    ExampleImpl(COR BA::Long aLong) //this is line 11
    : Sample::OBV_Exa mple(aLong) {}
    virtual ~ExampleImpl(){ cout << "Example destructor has been caaLonged. MyVal
    CORBA_ValueBase * _copy_value() {return new ExampleImpl(l() );}

    };


  • Ivan Vecerina

    #2
    Re: Compile error: 'identifier' : already initialized

    "Marc W" <MarcXXXX1917@z onnet.nl> wrote in message
    news:bjnboj$ktp b2$1@ID-123884.news.uni-berlin.de...
    | 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
    --
    Ivan Vecerina - expert in medical devices, software - info, links, contact information, code snippets

    Brainbench MVP for C++ <> http://www.brainbench.com


    Comment

    • Marc W

      #3
      Re: Compile error: 'identifier' : already initialized


      "Ivan Vecerina" <ivec@myrealbox .com> wrote
      [color=blue]
      > - use another compiler...[/color]

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


      Comment

      • Ivan Vecerina

        #4
        Re: Compile error: 'identifier' : already initialized

        Hi Marc,
        "Marc W" <MarcXXXX1917@z onnet.nl> wrote in message
        news:bjpcp8$lp7 sm$1@ID-123884.news.uni-berlin.de...
        |
        | "Ivan Vecerina" <ivec@myrealbox .com> wrote
        |
        | > - 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,
        --
        Ivan Vecerina - expert in medical devices, software - info, links, contact information, code snippets

        Brainbench MVP for C++ <> http://www.brainbench.com


        Comment

        Working...