Jul 20, 2008

Including Classes/lib's Twice

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

free web hosting

Including Classes/lib's Twice

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

Reply

dexter
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.

QUOTE
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.


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : including classes libs

  1. C++ Class - teach me classes (6)
    ok i know the basics of c++ exept for classes i just dont quite get them can someone teach me of
    point me to a good (video is nice) tutorial...
  2. Abstract Classes - and what they imply (2)
  3. Classes In C++ - (4)
    QUOTE C++ is a bunch of small additions to C, with a few major additions. One major addition is
    the object-oriented approach (the other addition is support for generic programming, which we'll
    cover later). As the name object-oriented programming suggests, this approach deals with objects. Of
    course, these are not real-life objects themselves. Instead, these objects are the essential
    definitions of real world objects. Classes are collections of data related to a single object type.
    Classes not only include information regarding the real world object, but also fun...



Looking for including, classes, libs

Searching Video's for including, classes, libs
advertisement



Including Classes/lib's Twice



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE