471,073 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

aCC Compiler error : Cannot use extern object of unknown size

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
3 2750

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

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

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.

Similar topics

19 posts views Thread by Alf P. Steinbach | last post: by
4 posts views Thread by Christopher M. Lusardi | last post: by
1 post views Thread by yanwan | last post: by
1 post views Thread by DiskMan | last post: by
3 posts views Thread by B Vidyadhar Joshi | last post: by
3 posts views Thread by dancer | last post: by
3 posts views Thread by Rene | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.