digitalmars.D - Template bugged?
- Patrick Kreft (40/40) Sep 18 2007 Is there an error?
- Sean Kelly (3/4) Sep 18 2007 Looks fine to me.
- BCS (25/25) Sep 18 2007 Reply to Patrick,
- Patrick Kreft (2/39) Sep 18 2007
- BCS (5/40) Sep 18 2007 I think that would also fail in C++. If not, than the difference is not ...
- Patrick Kreft (35/44) Sep 18 2007 Hmm it's work well on MinGW.
- Patrick Kreft (2/53) Sep 18 2007 ops i forget somewhat, nvm. and thx for help :)
Is there an error? I wrote down some ideas which i got for c++. private import std.stdio; class window { public void msgloop() { } } class application(applogic, subsystem) { this() { m_app = new applogic(); m_sub = new subsystem(); } public int execute() { m_app.run(); m_sub.msgloop(); return 0; } private { applogic m_app; subsystem m_sub; } } class DoHello { public void run() { writefln("Hello"); } } class HelloWorld : public application!(DoHello, window) { } class HelloWorld2 : public application!(HelloWorld2, window) { public void run() { writefln("Hello"); } } int main() { scope auto app = new HelloWorld(); // as HelloWorld2 Error at Runtime: StackOverflow return app.execute(); }
Sep 18 2007
Patrick Kreft wrote:Is there an error?Looks fine to me. Sean
Sep 18 2007
Reply to Patrick, lets rearrange that a bit class application(applogic) { this() { new applogic(); } } class HelloWorld2 : public application!(HelloWorld2) { } int main() { new HelloWorld2(); } now without the template stuff class application(applogic) { this() { new HelloWorld2(); } } class HelloWorld2 : public application { //implict this() made explict this(){super();} } int main() { new HelloWorld2(); } new HelloWorld2 calls HelloWorld2.this HelloWorld2.this calls application.this application.this calls new HelloWorld2 loop
Sep 18 2007
Ok i like C++ Template more :) BCS schrieb:Reply to Patrick, lets rearrange that a bit class application(applogic) { this() { new applogic(); } } class HelloWorld2 : public application!(HelloWorld2) { } int main() { new HelloWorld2(); } now without the template stuff class application(applogic) { this() { new HelloWorld2(); } } class HelloWorld2 : public application { //implict this() made explict this(){super();} } int main() { new HelloWorld2(); } new HelloWorld2 calls HelloWorld2.this HelloWorld2.this calls application.this application.this calls new HelloWorld2 loop
Sep 18 2007
Reply to Patrick,Ok i like C++ Template more :) BCS schrieb:I think that would also fail in C++. If not, than the difference is not a template issue. The issue is that a class news an instance of it's self for each instance of it's self. It's just hidden by the use of template base classesReply to Patrick, lets rearrange that a bit class application(applogic) { this() { new applogic(); } } class HelloWorld2 : public application!(HelloWorld2) { } int main() { new HelloWorld2(); } now without the template stuff class application(applogic) { this() { new HelloWorld2(); } } class HelloWorld2 : public application { //implict this() made explict this(){super();} } int main() { new HelloWorld2(); } new HelloWorld2 calls HelloWorld2.this HelloWorld2.this calls application.this application.this calls new HelloWorld2 loop
Sep 18 2007
BCS schrieb:Reply to Patrick,....I think that would also fail in C++. If not, than the difference is not a template issue. The issue is that a class news an instance of it's self for each instance of it's self. It's just hidden by the use of template base classesHmm it's work well on MinGW. #include <iostream> using namespace std; class windows { public: void msgloop() { std::cout << "MsgLoop" << std::endl; } }; template <class app, class subsystem = windows> class application { public: int execute() { _app->run(); _subsystem->msgloop(); return 0; } public: subsystem * _subsystem; app * _app; }; class HelloWorld : public application<HelloWorld> { public: void run() { std::cout << "HelloWorld" << std::endl; } }; int main() { HelloWorld app1; app1.execute(); std::cin.get(); return 0; }
Sep 18 2007
Patrick Kreft schrieb:BCS schrieb:ops i forget somewhat, nvm. and thx for help :)Reply to Patrick,....I think that would also fail in C++. If not, than the difference is not a template issue. The issue is that a class news an instance of it's self for each instance of it's self. It's just hidden by the use of template base classesHmm it's work well on MinGW. #include <iostream> using namespace std; class windows { public: void msgloop() { std::cout << "MsgLoop" << std::endl; } }; template <class app, class subsystem = windows> class application { public: int execute() { _app->run(); _subsystem->msgloop(); return 0; } public: subsystem * _subsystem; app * _app; }; class HelloWorld : public application<HelloWorld> { public: void run() { std::cout << "HelloWorld" << std::endl; } }; int main() { HelloWorld app1; app1.execute(); std::cin.get(); return 0; }
Sep 18 2007