【C++】template 統合スレ -- STL/Boost/Loki, etc.
■ このスレッドは過去ログ倉庫に格納されています
0293デフォルトの名無しさん
NGNG// ぜんぜん違うぞ、こうだ
#include <iostream>
class Foo
{
int m;
public:
Foo(int n = 0) : m(n)
{ std::cout << "Foo is created by " << n << std::endl; }
int val() const { return m; }
~Foo()
{ std::cout << "Foo is destroyed. m = " << m << std::endl; }
};
template <typename T> class Bar : public T
{
public:
Bar (int n = 0)
{
std::cout << "Bar is created by " << n << std::endl;
static_cast<T*>(this)->~T();
new (static_cast<T*>(this)) T(n);
}
~Bar()
{ std::cout << "Bar is destroyed." << std::endl; }
};
int main()
{
Bar<Foo>(10);
}
■ このスレッドは過去ログ倉庫に格納されています