//base.h
#ifndef __BASE_H__
#define __BASE_H__
#include <iostream>
using std::cout;
using std::endl;
class basePoint {
public:
void setPoint(int, int);
void display();
private:
int x;
int y;
};
#endif
//base.cpp
#ifndef __BASE_CPP__
#define __BASE_CPP__
#include "base.h"
void basePoint::setPoint(int x, int y) {
this->x = x;
this->y = y;
}
void basePoint::display() {
std::cout << x << " " << y << std::endl;
}
#endif
//main.cpp
#include "base.h"
int main(int argc, char* argv[]) {
basePoint bp0;
basePoint *bp1 = new basePoint();
bp0.setPoint(1, 2);
bp1->setPoint(3, 4);
bp0.display();
bp1->display();
return 0;
}
compile steps:
$ g++ -c base.cpp -o base.o
$ ar cr libbase.a base.o
$ g++ -c -I. main.cpp
$ g++ -o main main.o -L. -lbase
No comments:
Post a Comment