By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,035 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,035 IT Pros & Developers. It's quick & easy.

aCC Compiler error : Cannot use extern object of unknown size

P: n/a
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 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

ma*************@gmail.com 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.

Apr 21 '06 #2

P: n/a

Fei Liu wrote:
ma*************@gmail.com 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 '06 #3

P: n/a

Mi*************@tomtom.com wrote:
Fei Liu wrote:
ma*************@gmail.com 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.

Apr 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.