再会,
考虑以下代码,是否可以将原型 OOP 归类为
C++?
#include <iostream>
template< class... Bases >
struct TestClass : public Bases...
{
int a;
template< class... Parents >
TestClass< Parents... >* Create() {
return new TestClass< Parents... >();
}
TestClass< Bases... >* Create() {
return new TestClass< Bases... >();
}
};
struct Foo {
int fizz;
};
struct Bar {
int buzz;
};
int main()
{
TestClass< Foo > a;
a.a = 10;
a.fizz = 20;
std::cerr << a.fizz << "\n";
std::cerr << a.a << "\n";
auto b = a.Create();
b->fizz = 30;
std::cerr << b->fizz << "\n";
auto c = b->Create< Bar >();
c->buzz = 357;
std::cerr << c->buzz << "\n";
auto d = b->Create< Foo, Bar >();
d->fizz = 0;
d->buzz = 1;
std::cerr << d->fizz << "\n";
std::cerr << d->buzz << "\n";
return 0;
}
仅供参考,我忘了管理我的记忆,对不起!