Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > aCC Compiler error : Cannot use extern object of unknown size

Reply
Thread Tools

aCC Compiler error : Cannot use extern object of unknown size

 
 
manoj.pattanaik@gmail.com
Guest
Posts: n/a
 
      04-21-2006
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?

 
Reply With Quote
 
 
 
 
Fei Liu
Guest
Posts: n/a
 
      04-21-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) 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.

 
Reply With Quote
 
 
 
 
Michiel.Salters@tomtom.com
Guest
Posts: n/a
 
      04-21-2006

Fei Liu wrote:
> (E-Mail Removed) 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

 
Reply With Quote
 
Fei Liu
Guest
Posts: n/a
 
      04-21-2006

(E-Mail Removed) wrote:
> Fei Liu wrote:
> > (E-Mail Removed) 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference of extern short *x and extern short x[]? Andre C Programming 5 07-17-2012 07:38 PM
extern const char * vs. extern const char []http://tinyurl.com/47e3k Thomas Matthews C++ 5 08-02-2004 10:36 AM
Compiling the Python sources with a C++ compiler (aCC) Paul Sheer Python 3 06-21-2004 05:15 PM
Can we use <compiler> tag to avoid RunTime Compiler error? Jack Wright ASP .Net 5 01-19-2004 04:36 PM
Template instantiation on HP aCC compiler rpmohan C++ 4 10-24-2003 09:13 AM



Advertisments