Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Including Classes/lib's Twice
kvarnerexpress
post Jun 14 2005, 08:53 PM
Post #1


Super Member
*********

Group: Members
Posts: 407
Joined: 13-December 04
Member No.: 2,696



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!
Go to the top of the page
 
+Quote Post
dexter
post Jun 15 2005, 01:50 AM
Post #2


Advanced Member
*******

Group: Members
Posts: 142
Joined: 24-December 04
From: Queensland, Australia
Member No.: 2,902



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.

Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Including Php-made Images In A Page?(5)
  2. Php Classes(1)
  3. Php Parse Error(2)
  4. Including Files In Asp(1)
  5. > Google Can Find Anything.. Including Credit Card(4)
  6. Whats The Classpath (for The Packages) On Trap17(2)
  7. Jsp Application Design(2)
  8. Multiple Classes In Html(8)
  9. Ragnarok Online Forsaken Legends(0)
  10. Changing Php Classes Using Onclick(7)
  11. How To Make Youtube Embedded Videos Viewable On All Browsers(3)
  12. Classes In C++(4)
  13. Including An Imgs Clock For Your Web(1)
  14. C++ Class(6)
  15. Abstract Classes(2)
  1. Help! Not Able To Access The Entire Trap.com(3)
  2. Php Classes On Encryption(0)
  3. Poems Made By Request(0)
  4. Php Help Needed Including File In A Page.(2)
  5. I Finally Paid For My Acting Classes!(4)
  6. Classes(3)
  7. More Streaming At A Younger Age And More Randomly Split Classes.(7)
  8. Mp3 (compressed Digital Audio Including Aac, Mp3 And Such) Vs Cd Vs Tape Vs Vinyl(3)


 



- Lo-Fi Version Time is now: 2nd December 2008 - 11:15 AM