Jump to content
  • Advertisement
Sign in to follow this  
scitmon

console app problem

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
the class is too big to post code but this is the basic structure:



#include headers

class MyClass
{
// all class stuff here
}

MyClass MyClassObject; // tried here didnt work "syntax error"

int main
{
// also tried MyClass MyClassObject here "cant define here error"

}

Share this post


Link to post
Share on other sites
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."

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!