Jump to content
xisto Community
kvarnerexpress

Including Classes/lib's Twice

Recommended Posts

I'm using Dev-C++ as a compiler.(To use a classroom assignment as an example,) here is my problem...I've got classes Dog and Cat, which inherit from class Animal, (which uses iostream, stdlib, and some classes created by students) When I include both Dog and Cat in a new file, I get errors because I'm including libraries twice. (iostream included from Dog, and from Cat...)I can get around the problem by having Dog inherit Animal, and Cat inherit Dog (which sounds pretty idiotic, I know..I was just testing to see if the problem was really what I thought it was...) This is all on a PC at school, and I'm out for the summer, so I can't include the specific code...Please post if I'm not explaining myself well enough. Thanks!

Share this post


Link to post
Share on other sites

I always include whatever libraries are necessary for the class/file to compile fine without depending on other custom files.

So, anything that might need the iostream header, will have it included...

My only thought is that you haven't included the ifndef around the classes:

#ifndef DOG_H
#define DOG_H

#include <iostream>
#include "animal.h"

class Dog : public Animal {

};

#endif

I just did a test dummy up, and it worked fine.

This is all on a PC at school, and I'm out for the summer, so I can't include the specific code...Please post if I'm not explaining myself well enough.


You know, it's not really that hard to bump up a test case to recreate the problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.