Skip to content

Instantly share code, notes, and snippets.

@baobao
Created February 4, 2013 13:34
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/a7fe454e4f155a76140e to your computer and use it in GitHub Desktop.
Save baobao/a7fe454e4f155a76140e to your computer and use it in GitHub Desktop.
C++連想配列テストコード
#include <iostream>
#include <map>
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::map<int, Foo> list)
{
list[4].update();
}
int main(int argc, const char * argv[])
{
std::map<int, Foo> list;
int i;
for (i = 0; i < 10; i++)
{
Foo *fuga = new Foo;
fuga->init(i);
list.insert(std::map<int, Foo>::value_type(i, *fuga));
}
fooooo(list);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment