トップ
新規
一覧
単語検索
最終更新
ヘルプ
ログイン
アールメカブ
C++とヘッダ
をテンプレートにして作成
開始行:
[[Programming]]
まず cpp_test.h
//堀越 CPP; p.460
#ifndef CPP_TEST
#define CPP_TEST
#include <iostream>
#include <vector>
using namespace std;
class Xvec {
public:
vector <int> vec;
public:
Xvec ();
Xvec (vector <int> argvec);
void showVec();
void putVec(int i);
};
#endif
cpp_test.cpp
//#include <iostream>
//#include <vector>
#include "cpp_test.h"
using namespace std;
Xvec::Xvec(){
}
Xvec::Xvec(vector<int> argvec){
vec = argvec;
}
void Xvec::showVec(){
cout << vec.size() << endl;;
}
void Xvec::putVec(int i){
vec.push_back(i);
}
cpp_test_main.cpp
#include "cpp_test.h"
int main(){
Xvec x;
for(int i = 0; i < 8; i++){
x.putVec(i);
}
x.showVec();
return 0;
}
終了行:
[[Programming]]
まず cpp_test.h
//堀越 CPP; p.460
#ifndef CPP_TEST
#define CPP_TEST
#include <iostream>
#include <vector>
using namespace std;
class Xvec {
public:
vector <int> vec;
public:
Xvec ();
Xvec (vector <int> argvec);
void showVec();
void putVec(int i);
};
#endif
cpp_test.cpp
//#include <iostream>
//#include <vector>
#include "cpp_test.h"
using namespace std;
Xvec::Xvec(){
}
Xvec::Xvec(vector<int> argvec){
vec = argvec;
}
void Xvec::showVec(){
cout << vec.size() << endl;;
}
void Xvec::putVec(int i){
vec.push_back(i);
}
cpp_test_main.cpp
#include "cpp_test.h"
int main(){
Xvec x;
for(int i = 0; i < 8; i++){
x.putVec(i);
}
x.showVec();
return 0;
}
ページ名: