Whats wrong with this class?

This is killing me what is wrong with this definition?

#ifndef _MGAME_H
#define _MGAME_H

#include “main.h”
#include “MCamera.h”

class MGame
{
public:

MGame();
~MGame();

void draw();
void resizeWindow(int w, int h);
void keyboard( int key, int x, int y);
void keyboardUp( int key, int x, int y);

MCamera mCamera;

};

#endif

it says: declaration syntax error
MGame.h line 7 class MGame

I suspect the error is really in MCamera.h, towards it end.

EVERYTHINK IS PUBLIC AND THAT IS STUPID MAKE IT A STRUCT THEN

Mister 455h*L3, take it easy on your attitude there… Provide something more helpful than that…

///////////////////////////////////////

What is your error message…
There is nothing wrong with the class that I see… But you maybe including the a header somehwere twice, I dont know…

Try putting

#pragma once

in the very begining of you code…
Post your error messages…

I agree with dfey. I think you’re missing a semicolon after your class prototype in <dicknose>.h. Keep in mind that the program you’re actually compiling is the concatenation of the header and source files, so syntax errors in the header file will fall through the the source.

and to that 4hackerleetidiot guy: struct IS just a public class. they are interchangable, so why should he change his decl to struct? it’s semantically the same thing, anyway. (struct in C++ is just class with a default of public, rather than a class with a default of protected).

cheers
JOhn

Another thing is that he may not want to have the functions be accesible for anybody eccept for object instances of the class >>>>>>>>>>><<<<<<<<<<<<<<
So, since structs cant have function declarations in them, a class is the solution!
So, I think there is more than just a simple “make it a struct” issue here…
<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>

Besides… escozooz, why dont you post the code of the header file that maybe giving you problems…

…since structs cant have function declarations in them…

Try compile this piece of C++ code, and think about what you just said.

#include
using namespace std;
struct foo
{
void bar(void) {cout << “Hello world!” << endl;}
};
void main(void)
{
foo f;
f.bar();
}

As john said, the only, and I mean ONLY difference between a class and a struct is: A struct defaults to public members/inheritance, while a class defaults to private. There are NO other differences.

OK… I guess you learn something new everyday…

I was taught that you could not mix function with regular variables in a struct, so the solution were classes… I never tried mixing them both in a struct, since I took it for granted…

Well, thanx…

If you were programming pure C, you’d be right Mancha. In C++, however, it’s like John and Bob said… the only difference is default visibility.

I could be wrong, but when I learnt it I understood that classes were supposed to replace structs. Also, I’m a bit lazy, so I find it a lot easier to define class myclass, then create variables with myclass c1, c2; than to define struct mystruct, then create variables with struct mystruct s1, s2; or to use typedefs.

wow, I didn’t think this many people would respond. Thanks but the class MCamera was screwed up so it didn’t allow me to create this one.

Thanks for the responses and the actual class now has private function and variables, like 10 more.

I could be wrong, but when I learnt it I understood that classes were supposed to replace structs.

Both correct and wrong, depending on who you ask. Some people, including me, use structs for raw data storage containers, line file headers, and similar stuff. Since the file header structure’s job is only to hold the data, and not have any member functions that operates on the data, I use structs. Let’s say they were supposed to complement each other, but that’s just my oppinion, so not saying you’re wrong.

Also, I’m a bit lazy, so I find it a lot easier to define class myclass, then create variables with myclass c1, c2; than to define struct mystruct, then create variables with struct mystruct s1, s2; or to use typedefs

In C, when you defined a structure, you had to either typedef it, or declare a variable as struct mystruct s1;, just like you say. However, in C++, you no longer have to tyedef it, or put an extra struct infront of the definition. In C++ you can define a structure variable like any other type, mystruct s1;, just like with classes.

[This message has been edited by Bob (edited 04-30-2002).]

From Barney Soupstrop himself:

‘Which style you use depends on circumstances and taste. I usually prefer to use struct for classes that have all data public. I think of such classes as -not quite proper types, just data structures-.’

Which I find interesting, because this means that all the people who insist that every damn variable be private in every damn class are just stupid, since the creator himself knows that sometimes that is a waste of time.