C++とヘッダ の変更点 - アールメカブ

アールメカブ


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;
 }