Jump to content
  • Advertisement
Sign in to follow this  
amateur programmer

main class connected to two classes which have the same super class in C++

This topic is 4425 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 a bullets class and a enemies class which both are sprite objects and they also have their own specific methods. Eg bullets have damage property and enemies have a health property. C++ doesn't like me including these two classes as they both are sprite object. It thinks that enemy class redefines the sprite class. So what should I do? I included the definition of tboth classes into my main class otherwise they wont recognise the classes. #include "bullet.cc" #include "enemy.cc"

Share this post


Link to post
Share on other sites
Advertisement
It is possible that you are encountering the dreaded diamond inheritance problem. Here might be the answers to your questions.

Hope that helps,

Dave

Share this post


Link to post
Share on other sites
Why are you using .cc's instead of regular .h and .cpp files?

I would guess that your problem stems from multiple files including your sprite file, so it gets defined multiple times, which can be solved by using
#ifndef
#define
include guards, or on win32 by putting "#pragma once" at the beginning of a file.

Share this post


Link to post
Share on other sites
The standard extensions for C++ files are '.h' fo header and '.cpp' for source files. You should use these whenever possible.

As for your problem, the other posters above me have mentioned everything I guess. Don't ever include source files (you need to link them instead - for eg. by adding them to your project if you're using an IDE), just their headers, and don't forget to use include guards in the header files.

Share this post


Link to post
Share on other sites
Quote:
Original post by Morrandir
The standard extensions for C++ files are '.h' fo header and '.cpp' for source files. You should use these whenever possible.

As for your problem, the other posters above me have mentioned everything I guess. Don't ever include source files (you need to link them instead - for eg. by adding them to your project if you're using an IDE), just their headers, and don't forget to use include guards in the header files.


The C++ standard makes no mention of .cpp and .h (except for when talking about C header files), and the standard library's headers are extension-less. Many C++ gurus even use .hpp instead of .h (.h is for C header files, you shouldn't also use it for C++ headers). .cpp is pretty standard on Windows, on some platforms .cc is the standard for C++ source files.

Share this post


Link to post
Share on other sites
You're right, I didn't mean 'standard' as 'part of the C++ standard', a much better word would've been 'commonly used'.

I guess it's rather pointless to argue about these things anyway, it's just the question of personal preference...

Strange that I haven't heard about '.cc' for C++ source files before, although I have programmed on different platforms before...

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!