aCC Compiler error : Cannot use extern object of unknown size

M

manoj.pattanaik

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?
 
F

Fei Liu

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.
 
M

Michiel.Salters

Fei said:
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
 
F

Fei Liu

Fei said:
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.
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top