One class compiles one doesn't

So my Rect class compiles without a hitch. But any other class I try to make doesn’t.

error:

  
  
1>main.cpp  
1>c:\documents and settings\aaron\my documents\cpp\of_prerelease_v0.05_windows_vs_fat\of_prerelease_v0.05_windows_vs_fat\app\breakout\engine\src\testapp.h(13) : error C2146: syntax error : missing ';' before identifier 'test'  
1>c:\documents and settings\aaron\my documents\cpp\of_prerelease_v0.05_windows_vs_fat\of_prerelease_v0.05_windows_vs_fat\app\breakout\engine\src\testapp.h(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int  
1>c:\documents and settings\aaron\my documents\cpp\of_prerelease_v0.05_windows_vs_fat\of_prerelease_v0.05_windows_vs_fat\app\breakout\engine\src\testapp.h(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int  
1>testApp.cpp  
1>c:\documents and settings\aaron\my documents\cpp\of_prerelease_v0.05_windows_vs_fat\of_prerelease_v0.05_windows_vs_fat\app\breakout\engine\src\testapp.h(13) : error C2146: syntax error : missing ';' before identifier 'test'  
1>c:\documents and settings\aaron\my documents\cpp\of_prerelease_v0.05_windows_vs_fat\of_prerelease_v0.05_windows_vs_fat\app\breakout\engine\src\testapp.h(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int  
1>c:\documents and settings\aaron\my documents\cpp\of_prerelease_v0.05_windows_vs_fat\of_prerelease_v0.05_windows_vs_fat\app\breakout\engine\src\testapp.h(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int  
1>Generating Code...  
1>Compiling...  
1>Test.cpp  
1>Generating Code...  
1>Build log was saved at "file://c:\Documents and Settings\Aaron\My Documents\cpp\of_preRelease_v0.05_windows_VS_FAT\of_preRelease_v0.05_windows_VS_FAT\app\breakout\engine\obj\Debug\BuildLog.htm"  
1>emptyExample - 6 error(s), 1 warning(s)  
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========  
  

Here’s Rect’s header:

  
  
class Rect  
{  
public:  
	int x, y, width, height, cx, cy;  
	static const int UP = 1;  
	static const int RIGHT = 2;  
	static const int DOWN = 4;  
	static const int LEFT = 8;  
	static const int UP_RIGHT = 16;  
	static const int DOWN_RIGHT = 32;  
	static const int DOWN_LEFT = 64;  
	static const int UP_LEFT = 128;  
	Rect(int x, int y, int width, int height);  
	~Rect(void);  
	void updateCenter();  
	int contains(int x, int y);  
	static bool intersects(Rect& a, Rect& b);  
	int sideOf(int x, int y);  
	int sideOf4(int x, int y);  
};  
  

And here’s the header of Test - a class I got Visual Studio to plop in for me

  
  
class Test  
{  
public:  
	Test(void);  
	~Test(void);  
};  
  

And here’s the header of testApp (minus defines)

  
  
class testApp : public ofSimpleApp{  
	public:  
		Rect tile;  
		Test test;  
  
		void setup();  
		void update();  
		void draw();  
		  
		void keyPressed(int key);  
		void keyReleased(int key);  
		void mouseMoved(int x, int y );  
		void mouseDragged(int x, int y, int button);  
		void mousePressed(int x, int y, int button);  
		void mouseReleased();	  
};  
  

I haven’t included Rect but somehow it magically works and no other class I write will. What’s going on?

I don’t know why rect is working, but I suspect that there might be another rect class (or struct) in some other library that’s already defined.

for the most part, you have to include h files of the classes you use, or else you get errors like the ones you are getting now.

hope that helps!
zach

I put an include in at the top of testApp.h to include Test.h

  
  
#ifndef _TEST_APP  
#define _TEST_APP  
  
  
#include "ofMain.h"  
#include "ofAddons.h"  
#include "Test.h"  
  
class testApp : public ofSimpleApp{  
  

That doesn’t work. It tells me it can’t find Test.h but Test.h is in the src folder. I even tested the functionality of the Rect class beforehand so I know I got that right, but I can’t seem to make any other class work now.

I really have no idea but it shouldn’t be that hard. – can please you upload the cbp or a zip of everything?

thanks!
zach

Okay.

I figured it out basically.

I was going to write a full path into the include command to see if I could force it to see the file. But when I navigated to the folder I had a surprise. Visual Studio hadn’t moved my files to the src folder like the solution explorer suggested.

I could rant about how bloody annoying it is having a file browser that lies to me about the file structure but instead I’ll say that moving the files into the src folder where it said they were solved the problem.

So, here’s a lesson:

if Visual Studio says it can’t find the files then check they really are where they’re supposed to be

On VS 9 here.

Oh wait.

Now it doesn’t work. I’ve even copied the class files into another project and it still isn’t having any of it.

Here’s as far as I got:

http://www.robotacid.com/misc/engine2.zip

It’s saying there is no default constructor for testApp now.

I think you have some errors in usage, but VS is throwing errors that aren’t really helpful (no default constructor for testApp??) so I can see it being frustrating:

a) tile doesn’t have a default constructor:

  
  
class Tile  
{  
public:  
	int x, y, f, g, h;  
	Tile *parent;  
	int closed_id, open_id;  
	bool walkable;  
	Tile(int x, int y);  
  

b) you use it as if it does:

  
  
class testApp : public ofSimpleApp{  
	  
	public:  
		  
		Tile t;  
  

the errors it is throwing are not really helpful, but changing to Tile * t, for example, gets it to compile. you would have to construct it someplace, like:

t = new Tile(…);

in setup, for example…

hope that helps!

take care –
zach

Thanks.

Yes, I thought I was reserving a reference by doing that, which in Java usually forces a basic debug on the code for that reference.

I didn’t realise that I was actually constructing the object as soon as I asked for some memory for it. I’ve started putting in default constructor definitions now so that my code is more flexible.

Rect it appears is a part of some Quicktime library:

of_prerelease_v0.05_windows_vs_fat\of_prerelease_v0.05_windows_vs_fat\libs\qtdevwin\cincludes\mactypes.h

This is pretty annoying because I this class I use in all my other languages. I’m going to open it as a new topic.

Whilst I’m here, I just had hiccup trying to get a class to extend because it was complaining of redefinition.

I dropped in #pragma once (which my guess tells me that it says to the compiler - read this once only) and it compiled fine after that.

So should I be dropping in #pragma once on my much used classes or should I use that #ifndef stuff instead?

I think either is ok, but we’ve been using the #ifdefs, as had thought #pragma was non standard. I guess, reading up now, it’s more universal then I had thought and a worthy alternative.

some good info here:
http://en.wikipedia.org/wiki/Pragma-once

take care!
zach