C++ Class Declaration on SS

Well, I have started coding my own classes for the SS but the SS compiler doesn't want to compile a simple class declaration like this:

#include "sgl.h"

#ifndef _OBJECT3D_INC

#define _OBJECT3D_INC

class Object3D{

POLYGON *cares;

POINT *vertex;

ATTR *atributs_cares;

public:

Object3D(){}



};

Edit: It was a problem on the compiler line. Sorry, Already solved.

#endif

Am I doing sth wrong ??? Does class declaration need sth special ?
 
Well, it wasn't as easy as I expected... I did a litle research and it seems it isn't so trivial to make C++ classes compile at the same time you use the SGL.
 
You'll probably have to make your own link script, the one included with SGL is very basic. The startup file may have to be modified as well. If you're trying to use the Sega compiler you'll also run into problems with its (at this point) poor C++ support.
 
Another option would be to use C structs. If I recall correctly, you can have functions inside the class as well (or was that only in C++ :huh ).
 
Originally posted by slinga@Oct 18, 2003 @ 01:40 PM

Another option would be to use C structs. If I recall correctly, you can have functions inside the class as well (or was that only in C++ :huh ).

That's only in C++, but you could have function pointers inside a struct and that would achieve as similar goal, but I don't think there's a *this pointer so you'd probably have to pass a pointer to the object when you made a call.
 
The fact is that I simply included Object3D.h from a file that already compiled succesfully.

The problem I faced was that the SH compiler (last version from renesas) ignored the C++ class declaration.

Then I realised that in GCC when you want to compile C++ code you have to use G++. I changed that in the makefile but then the problem was that the file that already compiled couldn't find the SGL functions that it was using.

Curious...

I have no problem using C structs instead of C++ classes. I only wanted to use C++ classes because it's easier to understand and organize your code.
 
In a C++ source file, if you want to use modules written in C you must declare the functions as C functions using 'extern "C"'. You can do it for a single function like so:

Code:
extern "C" int foo(char *bar);

or

extern "C" {

int foo(char *bar);

}

The second way lets you include complete C headers:

Code:
extern "C" {

#include "myclib.h"

#include "myotherclib.h"

}

Variables can also be declared like that, see a C++ book for more info (eg. Stroustrup, The C++ Programming Language, §9.2.4)
 
Oh, yes I see (but I think that in the latest versions of C/C++ compilers this wasn't necessary). But it's not that a C++ file includes a C one but just the oposite: a C file that includes a C++ one, and I think that's possible and valid. At least I haven't had any problems when I have done it on PC.

Probably it's a problem with the makefile and all the stuff GCC needs. As I have said in other topics I am not a pro with makefiles and all that stuff and I don't want to spend more time on it since it's frustrating and doesn't bring you to anywhere.

I will code using classic C.
 
You need the extern "C" on any C++ functions called from C functions as well. Some compilers may let you leave it out, but it's not standard C++.

EDIT: To be precise, the construct doesn't say that the function is a C function, but that it should be linked as one. This page should illustrate how to mix the languages in practice.
 
I succeeded in compiling C++ code called from a C file. Well, not really since the thing to compile was only the include line.

However, I haven't had any luck in compiling a C++ call from a C++ main. Meaning that all the code is C++. Probably due to the makefile and all the stuff.
 
Back
Top