console app problem

Started by
3 comments, last by scitmon 18 years, 8 months ago
I have developed a console application in Borland C++ but i have a small problem that i am confused with. I have defined a class, and int main() i tried to create an object of my class in the body of main() but it rejected it saying that it "may not be defined here" if you cant define it in main, where can you define it?
Advertisement
How did you define your class, and how did you try to create an object of it? Show us some code.

Did you declare your class AFTER defining the main? If so, do this ABOVE the main:
class ClassName;

That will tell the compiler your class will exist, but will be defined elsewhere. Downside is you can only create a pointer to it. Otherwise you could either move the class into it's own .h file and/or move it above the main.

Toolmaker

the class is too big to post code but this is the basic structure:

#include headersclass MyClass{   // all class stuff here}MyClass MyClassObject;  // tried here didnt work "syntax error"int main{// also tried MyClass MyClassObject here "cant define here error"}
Are you sure that you have all your semi-colons in place? Strange things can happen when you forget those; otherwise, I'd need more info (code) on the exact problem/error.

:stylin: "Make games, not war."
:stylin: "Make games, not war.""...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
ah the classic forgot the semi colon error...

fixed now

cheers :)

This topic is closed to new replies.

Advertisement