我这样做对吗?我正在尝试委托一个 C++ 类构造函数,因为它基本上是相同的代码重复 3 次。我阅读了 C++x11 并读到 g++ 4.7.2 允许这样做,但我不确定我是否正在这样做对:
Bitmap::Bitmap(HBITMAP Bmp)
{
//Construct some bitmap stuff..
}
Bitmap::Bitmap(WORD ResourceID)
{
HBITMAP BMP = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(ResourceID), IMAGE_BITMAP, 0, 0, LR_SHARED);
Bitmap(BMP); //Delegates to the above constructor? Or does this create a temporary?
}
或者我需要做什么:
Bitmap::Bitmap(HBITMAP Bmp)
{
//Construct some bitmap stuff..
}
Bitmap::Bitmap(WORD ResourceID) : Bitmap((HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(ResourceID), IMAGE_BITMAP, 0, 0, LR_SHARED))
{
}