Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

tryandgetme

help with class constructors

This topic is 6218 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

hi all. I wrote a class for a simple game I'm making, and I'm getting stuck with the constructor. I've never had problems with classes before cause I've never needed constructors. I wrote the class and constructor with the tutorial right beside me, and as far as I can see from the tutorial, it should work. the compiler is giving me the error: chopper.cc:34: return type specification for constructor invalid here's the class and it's constructor class chopper { public: chopper(); ~chopper(); private: int angle; int turnrate; float x, y, currentspeed, maxspeed, accel ,drag; void userinput(); void animate(); }; chopper::chopper() { /*this is the line it's complaining about*/ angle = 0; x = 320; y = 200; maxspeed = 10; currentspeed = 0; accel = 0.25; turnrate = 4; drag = 0.1; } thanks for any help you can give btw, is this the best place to post these type of questions, or should I go somewhere else, like general? Edited by - tryandgetme on September 5, 2001 2:03:30 PM

Share this post


Link to post
Share on other sites
Advertisement
Your class compiles without any errors with VC++. It only gives a warning that the value assigned to drag is converted from const double to float which can be avoided by writing an "f" behind the number (drag = 0.1f.
I hope you also defined the destructor of the chopper class. When I created an instance of class chopper it complained that the destructor isn''t defined. (needs something like chopper::~chopper() { /*destroy object*/ })
Which compiler are you using? VC++ needs the extension .cpp for c++ source files.Maybe you just have to recompile everything.

baumep

Share this post


Link to post
Share on other sites
I'm using the DJGPP compiler for dos (www.djgpp.org). it did everything just fine until I added the constructor and destructor. maybe I should stop calling it names hmm...I guess I'll just keep working at it and see what I come up with. anyone out there use the DJGPP compiler and have this problem?
and, if no one can help me with that, can you help me understand the error message better?

Edited by - tryandgetme on September 5, 2001 6:47:09 PM

Share this post


Link to post
Share on other sites
ok, I did some fiddling around, tried devc++ (www.bloodshed.net) , djgpp, and the compiler that comes with Redhat linux 7, and ms visual c++. the error only happens when using linux, devc++ or djgpp. devc++ and linux both use the gcc compiler, and devc++ uses mingw. does this make any sense to anyone?

Share this post


Link to post
Share on other sites
This is against all rules of c++ and may sound crazy but probably your compiler expects a void return type to the definition of the constructor.
Try to implement your constructor as void chopper::chopper() {...} and see if it results in an error (it should). Or try putting a void before the declaration of the constructor.

baumep

Share this post


Link to post
Share on other sites
As it turns out, I did make my class right, but made a typeing error that took me a week to catch. everything works great now. Thanks for your help.

Share this post


Link to post
Share on other sites

  • 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!