include problem

This is a discussion on include problem within the C++ Programming forums, part of the General Programming Boards category; okay, I've got three files. book.h (header for class Book), book.cc (implementation for class Book), and main.cc (application file). I'm ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    46

    include problem

    okay, I've got three files. book.h (header for class Book), book.cc (implementation for class Book), and main.cc (application file). I'm including book.cc in book.h and book.h in main.cc. but for some reason it's not working at all. it doesn't recognize Book as a class and everything is undefined. it works if I include the header in the implementation then the implemenation in the main, but that defeats the point of the class doesn't it? here's what it looks like:

    Code:
    '
    //in book.cc
    #include <iostream>
    #include <cstdlib>
    #include <string>
    #include <fstream>
    #include <cctype>
    #include <cmath>
    
    using namespace std;
    
    //in book.h
    
    #include "book.cc"
    
    //in main.cc
    
    #include "book.h"
    like I said, it works if I do it the opposite way, but that defeats the purpose of hiding the implementation

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,198
    This is how it should look like in main.cc
    Code:
    // Other includes
    #include "book.h"
    And in book.cc:
    Code:
    // Other includes you need
    #include "book.h"
    Just for future reference: you should never include cc, cpp or those kind of files.
    Last edited by Shakti; 01-31-2005 at 01:02 PM.

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Lookup header guards

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    46
    now I'm getting a symbol referencing error. here's how my include, typedef, and namespace statements look:

    Code:
    //in book.cc
    
    #include <iostream>
    #include <cstdlib>
    #include <string>
    #include <fstream>
    #include "book.h"
    
    using namespace std;
    
    //in book.h
    
    #include <string>
    
    using namespace std;
    
    typedef string* strptr
    
    //in main.cc
    
    #include <iostream>
    #include <fstream>
    #include "book.h"
    
    using namespace std;
    is that right? if it is, it might be something else I messed up on

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    That is correct. It is the linker, not the compiler that is screaming at you. Compile book.cc (now it will create a book.o or book.obj, or some other object file -- extension dependent on compiler). Now compile and build main.cc.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with simple socket client/server program
    By spencer88 in forum C Programming
    Replies: 6
    Last Post: 05-05-2009, 11:05 PM
  2. debug assertion failed!
    By chintugavali in forum C Programming
    Replies: 4
    Last Post: 12-11-2007, 05:23 AM
  3. Sending problem, or 1 = smiley face
    By Asmodeus in forum Tech Board
    Replies: 1
    Last Post: 04-25-2005, 11:01 AM
  4. Read and write hanging
    By zee in forum C Programming
    Replies: 8
    Last Post: 08-03-2004, 11:19 PM
  5. help with finding lowest number entered
    By volk in forum C++ Programming
    Replies: 12
    Last Post: 03-22-2003, 12:21 PM

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