jnancheta
jnancheta

Reputation: 7408

Porting to Solaris SPARC using Sun Studio 12

I am trying to compile an object file using the code below.

//--Begin test.cpp
class A;

void (A::* f_ptr) ();

void test() {
    A *a;
    (a->*f_ptr)();
}
//-- End test.cpp

For GNU g++ compiler, it is able to compile the object file.

$ g++ -c test.cpp

But for Sun Studio 12 on a Solaris 10 (SPARC), it outputs an error.

$ CC -c test.cpp

"test.cpp", line 7: Error: Cannot call through pointer to member function before defining class A.

1 Error(s) detected.

Is there a compiler flags to get the Sun Studio C++ compiler to build the object file? Is there another workaround?

Upvotes: 0

Views: 289

Answers (2)

Rodyland
Rodyland

Reputation: 558

You'll find that there are a lot of things that g++ lets you get away with that sunpro will complain about, and vice-versa.

Be prepared for a lot of this sort of thing.

GMan's answer looks right to me.

Upvotes: 0

GManNickG
GManNickG

Reputation: 504223

Try to #include <A.h> in that file. The compiler needs to know what class A looks like.

Upvotes: 2

Related Questions