class MyMap : std::map<char, pro::image>
{
public:
void MyMethod(char x);
/** code **/
}
void MyMap::MyMethod(char x)
{
pro::image my_img; // note that my_img is a local variable
my_img.LoadFromFile("my_image.png");
this->insert(std::pair<char, pro::image>(x, my_img)); // stored in the class
}
이제이 코드는 안전한가요? 기본적으로 MyMap
은 insert
일 때 복사본이 my_img
일 때 저장합니까? 아니면 참조을 저장할 때입니까?클래스 변수에 STL 컨테이너에 로컬 변수를 저장하고 있습니까?
안전합니다. 그러나 std :: map에는 비가 상 소멸자가 있으므로이 인스턴스를 상속해서는 안됩니다. – mfontanini
이것은'pro :: image'의 복사 생성자만큼 안전합니다. 'pro :: image'가 안전하게 복사 될 수 없다면,'std :: map'는 안전하지 않습니다. –