Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active April 6, 2018 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baobao/fcc173957ba81a30eb2f to your computer and use it in GitHub Desktop.
Save baobao/fcc173957ba81a30eb2f to your computer and use it in GitHub Desktop.
C++vectorテストコード
#include <iostream>
#include <vector>
class Foo
{
public:
Foo(){
std::cout<<"constructor"<<"\n";
}
~Foo(){
std::cout<<"destructor"<<"\n";
}
void init(int id);
void update();
int _id;
};
void Foo::init(int id)
{
_id = id;
}
void Foo::update()
{
std::cout<<"update::id::"<<_id<<"\n";
}
void fooooo(std::vector<Foo> arr)
{
//配列の中身実行
for (int i = 0; i < arr.size(); i++)
{
arr[i].update();
}
}
int main(int argc, const char * argv[])
{
std::vector<Foo> array;
int i;
for (i = 0; i < 10; i++)
{
Foo *fuga = new Foo;
//ポインタへのアクセスは->アローシンタックス
fuga->init(i);
//参照をvectorに渡す
array.push_back(*fuga);
}
fooooo(array);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment