Question on where to #include my library

This is a discussion on Question on where to #include my library within the C++ Programming forums, part of the General Programming Boards category; hey guys: getting a problem when i'm #including into my files here.. i'm getting multiple definitions of my adjacency list... ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    63

    Question on where to #include my library

    hey guys:

    getting a problem when i'm #including into my files here.. i'm getting multiple definitions of my adjacency list... here is my situation..

    i have a graph.cpp graph.hpp and a driver.cpp

    the .hpp is my header for the graph class, i want to be able to use the adjacency list across the program and i included it in the .hpp file.. but i get the double declaration error cuz i # include the graph.hpp into both of my .cpp's..

    i hope that makes sense.. puhleeze.. reply..

    thanks
    SS3X

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    just do this.......::

    Code:
    #ifndef  GRAPH_HPP
    #define GRAPH_HPP
    
    { // do your code here}
    
    #endif

    this will make sure that whenever you call to preprocessor to include this file in the source code, if it is already included then it will not declrare it again....

    and you should be ok...

    Regards,

    matheo917

  3. #3
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    ohhhhh......... and this is ofcourse inside of you Graph.hpp function....... just put this stuff in front and at the end of your source code ...

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    put this stuff in front of and behind what?? LOL

    ok so in each .cpp put that? thanks for the quick reply..
    SS3X

  5. #5
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    no no.......this is in your Graph.hpp

    your header file......

    these 2:

    #ifndef GRAPH_HPP
    #define GRAPH_HPP

    go before any code in your Graph.hpp

    and this 1;

    #endif

    goes after all the code has ended in your Graph.hpp .....

    quick summarytranslation) "if Graph.hpp is not defined then define it.....and then end the if statement....."

    that's all


    sorry for a little confusion....i tend to type little too fast sometimes....

    Good Luck...

    matheo917

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    actually that was already in my graph.hpp

    the TA gave us these three "driver files" he created and we need to use.. so like i said that was in the graph.hpp where i include my adjlist.cc

    kinda weird.. what u said made sense.. thanks for the reply again.
    SS3X

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    and i'm stil gettin the error.. lol
    SS3X

  8. #8
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    i think i don't fully understand your question and situation.....

    if this is not something urgent then e-mail me all of your files and I will look at it tomorrow, for now i have to hit the bed b/c i am way too tired....plus if you can refrase your ? or problem a bit

    e-mail: matheo917@comcast.net

    Regards,
    matheo917

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    i'll email it off.. not a problem.. thanks for all the help!
    SS3X

  10. #10
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    well it turns out that i had an adjlist.h to use.. so i #included that instead.. now i get three smaller errors in my proggy.. they are these

    undefined reference to ... bla bla bla..

    lemme know if you can assist further..

    thanks
    SS3X

  11. #11
    Registered User WebSnozz's Avatar
    Join Date
    Oct 2001
    Posts
    102
    on gamedev.net there is an article somewhere about how to fix a few quarky things that come up as far as including files that might help you, also might wanna make sure whatever files you are given to use by someone else,even if they claim to be a god, has the if define thingy in there to.
    http://www.gamedev.net/reference/pro...ures/orgfiles/
    http://www.gamedev.net/reference/pro...ures/orgfiles/
    WebSnozz-
    Cats have no butt cheeks.
    If one farted, then it would make a flute noise.

  12. #12
    Registered User
    Join Date
    Apr 2002
    Posts
    1

    You Fail

    As noted in the course policies, help from anyone other than the TA's and the instructor is not permitted in this class. I am turning in the paperwork that will dismiss you from CS202. I have made a note of your real name.

  13. #13
    Registered User Sekti's Avatar
    Join Date
    Feb 2002
    Posts
    163
    lol what courses are these
    +++
    ++
    + Sekti
    ++
    +++

  14. #14
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    thats funny..
    SS3X

  15. #15
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    good does that mean no more dumb programs to write?
    SS3X

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Include some function form library
    By thepolo in forum C Programming
    Replies: 4
    Last Post: 05-24-2009, 06:11 PM
  2. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 10:08 PM
  3. Simple question, LINE_MAX
    By rkooij in forum C Programming
    Replies: 6
    Last Post: 03-14-2006, 08:03 AM
  4. Newbie Question: Can't use #include <string>
    By JohnnyCat in forum C++ Programming
    Replies: 7
    Last Post: 01-07-2005, 02:51 PM
  5. Question with Winamp Library
    By moonwalker in forum Tech Board
    Replies: 3
    Last Post: 08-07-2003, 09:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21