Linking structs together
March 18, 2009 03:47PM
I'm used to Visual C++ (PC), so it's still taking a minute to adapt to DevKitPPC (though I'm doing fine too :)

At the moment I have a math header with a struct I call "vector2f"
struct vector2f {
public:
	vector2f () {}

	vector2f (float X, float Y) { 
		x = X; y = Y;
	}

	vector2f& operator= (vector2f v) {
	...

When I want to use vector2f all is fine - example: vector2f vert(x, y);

But If I want to use it inside of another struct then it fails to link
typedef struct CLocation {
	...
	vector2f		vert[width+1][height+1];
	...

The only way I can link it, is to define both structs inside of the same header file...which isn't ideal in the long run.

How might I compile the above 2 structs in different header files please? (I'm guessing something simple like defining them as classes?)
Re: Linking structs together
March 18, 2009 11:21PM
It sounds like you want to include one header file inside of another, so you would do something like this:

#include <header_with_vector2f.h>
typedef struct CLocation {
	...
	vector2f		vert[width+1][height+1];
	...

Michael
Re: Linking structs together
March 19, 2009 12:12AM
Thanks for reply. To confirm, the header is included and the "vector2f" struct is fine if used outside of the 2nd struct. This would compile on PC, but not in DevKitPro without both structs being in the same header file. Typedef'ed "s32" etc work fine inside the 2nd struct. But where is "int" defined? That links fine inside a struct of course ;)

"error: 'vector2f' does not name a type"

It's as if the linker is not doing a pass 2 on unknowns as all headers contain a "#pragma once"
Re: Linking structs together
March 19, 2009 03:47AM
From what you've posted it sounds like it should work. If you have the time/energy, post a simple example which reproduces the error and maybe something will stand out.

Michael
Re: Linking structs together
March 19, 2009 06:40AM
Quote

#include <header_with_vector2f.h>
typedef struct CLocation {
	...
	vector2f		vert[width+1][height+1];
	...

I'd guess that the error is caused by passing in width and height that way. I don't believe even in VC++ you can do that. The parameters must be constants if your defining vert within a class. Try "vector2f vert[1][1];" as a test! Think about it how is vert going to know the values of width and height when it's being defined?
Re: Linking structs together
March 19, 2009 10:19AM
vector2f		vert[width+1][height+1];
This needs to be allocated dynamically (if width and height aren't constants), doesn't it.?


EDIT:
I didn't read the post just above carefully enough, sry.

#include <header_with_vector2f.h>

This is looking for a file header_with_vector2f.h in the directories that you passed with the -I to the compiler.
If you're including a file from a folder that is not in one of this directories use double quotes.

#include "header_with_vector2f.h"



Edited 3 time(s). Last edit at 03/19/2009 10:45AM by koopa.
Re: Linking structs together
March 19, 2009 03:39PM
Good points. Another problem that can cause the "error: 'vector2f' does not name a type" message is if you also have a function or variable in the same scope called vector2f. You might also try re-arranging the order of your #includes to see if it's an include order issue.

Michael
Re: Linking structs together
March 19, 2009 04:20PM
Thanks for replies...

Michael, indeed it should work, I'm more or less using code from my PC projects. If I still have no joy later today then I will post a test project which fails the same way. But reading your 2nd post, I will next try to 'start over' with including files only where needed...I've tended to for example gx.cpp includes gx.h, which in turn includes main.h, which includes all of my headers!

scanff, yes width and height are defined as constants...I did test with "vector2f vert[1][1];" and get the same compile error...actually I get it when my camera class tries accessing vector2f too, so right now my math class has all of the structs in the 1 header! Must sort this lol

koopa, sorry I should have clarified that I am including local files with the quotation marks already.

I'll start over with where and when I include my headers...
Re: Linking structs together
March 19, 2009 05:08PM
That was it! And will teach me to practice my includes correctly!

Bonus is of course that I can now edit a header without every other file having to recompile too. Thanks PPC for being fussy, MS' VC had me doing things the lazy way.

Thanks all for the help, my Wii code is now a lot less claustrophobic :)


edit: oh and for the record, I didn't actually use "width" as a global name, that would be silly!
#define			maxLocationWidth			1024
#define			maxLocationHeight			128
vector2f		vert[maxLocationWidth+1][maxLocationHeight+1];
Perhaps I'll allocate that when the level grows ;)



Edited 1 time(s). Last edit at 03/19/2009 05:31PM by blitter.
Sorry, only registered users may post in this forum.

Click here to login