目录结构如下
test.h的定义如下:
#ifndef TEST_H
#define TEST_H
#include<vector>
#include<string>
using namespace std;
class Box{
public:
vector<int> myVector;
void putData(int data);
bool isEmpty();
};
#endif
test.cpp的定义如下
#include <iostream>
#include "../../include/test.h"
void Box::putData(int a){
myVector.push_back(a);
}
bool Box::isEmpty(){
bool temp = myVector.empty();
return temp;
}
main.cpp函数的定义
#include <iostream>
#include "include/test.h"
using namespace std;
int main(){
Box box;
box.putData(10);
box.putData(20);
bool isEmpty_ = box.isEmpty();
auto iter = box.myVector.begin();
for(;iter != box.myVector.end(); iter++){
std:: cout << *iter << endl;
}
cout << isEmpty_ << endl;
return 0;
}
Linux下的运行指令
g++ -o test tools/bases/test.cpp main.cpp
./test