|
Sorry about that I can't input Chinese under Ubuntu environment..test
hehe
I'm a c++ rookie..
Followed by the problem:
I create 3 independant files named "sample.cpp","bank.h","bank.cpp".
sample.cpp -- the application source file,which include the header file bank.h;
bank.h -- the header file, but only contain the interface,that is,no implementation but only declaration of funtions.
bank.cpp -- the implementation of the header file.
Then I created a makefile like this:
//makefile//
sample:sample.o
g++ -o sample sample.o
sample.o:sample.cpp bank.h
g++ -c sample.cpp
//end//
the compilation is OK,while the link encountered a problem -- indicating the functions ,which are members of the class defined in the header file, are undeclared.BUT once I put the declaration part and the inplementaion part together in a SINGLE header file then everything is fine..YUMEN...
Help~~
bank.h
//begin..
#include<iostream>
using namespace std;
class bank
{
public:
void print_money();
private:
int money;
};
bank.cpp
//begin
#include<iostream>
#include"bank.h"
using namespace std;
void bank::print_money()
{
cout<<money<<endl;
} |
|