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