aCC Compiler error : Cannot use extern object of unknown size

Discussion in 'C++' started by manoj.pattanaik@gmail.com, Apr 21, 2006.

  1. Guest

    Hi,
    I am trying to compile following piece of code (bb.cpp) using aCC (HP
    ANSI C++ B3910B A.03.37) compiler on HP-UX 11.23. It gives error:485

    //bb.cpp -- Starts

    #include <iostream>
    using namespace std;

    class abc;

    extern abc objabc;


    template <class a>
    class def
    {
    public:
    void disp()
    {
    objabc.func();
    }
    };


    class abc
    {
    public:
    void func()
    {
    cout<<"from func"<<endl;
    }
    };

    abc objabc;

    //bb.cpp -- Ends

    aCC -AA -c bb.cpp -o bb.o

    Error 485: "bb.cpp", line 17 # Cannot use extern object of unknown
    size; 'abc' must be defined first. "abc objabc" was declared at
    ["bb.cpp", line 8].
    objabc.func();
    ^^^^^^
    Same code is compiling fine with VC++ (Windows), CC (Solaris 9), gcc
    (LInux). Can anyone please help me to compile it with aCC compiler on
    HPUX?
    , Apr 21, 2006
    #1
    1. Advertising

  2. Fei Liu Guest

    wrote:
    > Hi,
    > I am trying to compile following piece of code (bb.cpp) using aCC (HP
    > ANSI C++ B3910B A.03.37) compiler on HP-UX 11.23. It gives error:485
    >
    > //bb.cpp -- Starts
    >
    > #include <iostream>
    > using namespace std;
    >
    > class abc;
    >
    > extern abc objabc;
    >
    >
    > template <class a>
    > class def
    > {
    > public:
    > void disp()
    > {
    > objabc.func();
    > }
    > };
    >
    >
    > class abc
    > {
    > public:
    > void func()
    > {
    > cout<<"from func"<<endl;
    > }
    > };
    >
    > abc objabc;
    >
    > //bb.cpp -- Ends
    >
    > aCC -AA -c bb.cpp -o bb.o
    >
    > Error 485: "bb.cpp", line 17 # Cannot use extern object of unknown
    > size; 'abc' must be defined first. "abc objabc" was declared at
    > ["bb.cpp", line 8].
    > objabc.func();
    > ^^^^^^
    > Same code is compiling fine with VC++ (Windows), CC (Solaris 9), gcc
    > (LInux). Can anyone please help me to compile it with aCC compiler on
    > HPUX?


    since you referred to objabc.func();, the definition of class abc must
    be known prior to this reference.
    Fei Liu, Apr 21, 2006
    #2
    1. Advertising

  3. Guest

    Fei Liu wrote:
    > wrote:
    > > Hi,
    > > I am trying to compile following piece of code (bb.cpp) using aCC (HP
    > > ANSI C++ B3910B A.03.37) compiler on HP-UX 11.23. It gives error:485
    > >
    > > //bb.cpp -- Starts
    > >
    > > #include <iostream>
    > > using namespace std;
    > >
    > > class abc;
    > >
    > > extern abc objabc;
    > >
    > >
    > > template <class a>
    > > class def
    > > {
    > > public:
    > > void disp()
    > > {
    > > objabc.func();
    > > }
    > > };
    > >
    > >
    > > class abc
    > > {
    > > public:
    > > void func()
    > > {
    > > cout<<"from func"<<endl;
    > > }
    > > };
    > >
    > > abc objabc;
    > >
    > > //bb.cpp -- Ends
    > >
    > > aCC -AA -c bb.cpp -o bb.o
    > >
    > > Error 485: "bb.cpp", line 17 # Cannot use extern object of unknown
    > > size; 'abc' must be defined first. "abc objabc" was declared at
    > > ["bb.cpp", line 8].
    > > objabc.func();
    > > ^^^^^^
    > > Same code is compiling fine with VC++ (Windows), CC (Solaris 9), gcc
    > > (LInux). Can anyone please help me to compile it with aCC compiler on
    > > HPUX?

    >
    > since you referred to objabc.func();, the definition of class abc must
    > be known prior to this reference.


    Well, that's not precisely true, as we're talking templates here.
    They're compiled
    in one context and perhaps instantiated in another. However, the
    solution is
    obvious: Either include the header that defines class abc, or (better)
    remove the
    object from the header, wrap the call in a non-template function and
    put that
    function declaration in the header instead. This works because
    objabc.func()
    doesn't depend on the template type.
    For better encapsulation, the wrapper function can be made a protected
    method
    of a private non-template base class.

    HTH,
    Michiel Salters
    , Apr 21, 2006
    #3
  4. Fei Liu Guest

    wrote:
    > Fei Liu wrote:
    > > wrote:
    > > > Hi,
    > > > I am trying to compile following piece of code (bb.cpp) using aCC (HP
    > > > ANSI C++ B3910B A.03.37) compiler on HP-UX 11.23. It gives error:485
    > > >
    > > > //bb.cpp -- Starts
    > > >
    > > > #include <iostream>
    > > > using namespace std;
    > > >
    > > > class abc;
    > > >
    > > > extern abc objabc;
    > > >
    > > >
    > > > template <class a>
    > > > class def
    > > > {
    > > > public:
    > > > void disp()
    > > > {
    > > > objabc.func();
    > > > }
    > > > };
    > > >
    > > >
    > > > class abc
    > > > {
    > > > public:
    > > > void func()
    > > > {
    > > > cout<<"from func"<<endl;
    > > > }
    > > > };
    > > >
    > > > abc objabc;
    > > >
    > > > //bb.cpp -- Ends
    > > >
    > > > aCC -AA -c bb.cpp -o bb.o
    > > >
    > > > Error 485: "bb.cpp", line 17 # Cannot use extern object of unknown
    > > > size; 'abc' must be defined first. "abc objabc" was declared at
    > > > ["bb.cpp", line 8].
    > > > objabc.func();
    > > > ^^^^^^
    > > > Same code is compiling fine with VC++ (Windows), CC (Solaris 9), gcc
    > > > (LInux). Can anyone please help me to compile it with aCC compiler on
    > > > HPUX?

    > >
    > > since you referred to objabc.func();, the definition of class abc must
    > > be known prior to this reference.

    >
    > Well, that's not precisely true, as we're talking templates here.
    > They're compiled
    > in one context and perhaps instantiated in another. However, the


    objabc is a non-dependent name and will be looked up during declaration
    by a standard confoming compiler.
    Fei Liu, Apr 21, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rpmohan
    Replies:
    4
    Views:
    1,664
    Dennis Handly
    Oct 24, 2003
  2. Thomas Matthews
    Replies:
    5
    Views:
    2,413
    tom_usenet
    Aug 2, 2004
  3. Paul Sheer
    Replies:
    3
    Views:
    389
    Paul Sheer
    Jun 21, 2004
  4. Vincent Arnoux
    Replies:
    1
    Views:
    241
    Arnaud Bergeron
    Aug 11, 2006
  5. Andre
    Replies:
    5
    Views:
    535
    Keith Thompson
    Jul 17, 2012
Loading...

Share This Page