Quote:Original post by DigitalDelusion
*** Source Snippet Removed ***
works without problems using VC7.1
edit:
without problems as in compiles and dutifully leaks memory.
Well, it doesn't work.
D:\Cyprox Studios\The King Of Gods\QuickCode\main.cpp(358) : error C2062: type 'int' unexpectedD:\Cyprox Studios\The King Of Gods\QuickCode\main.cpp(359) : error C2275: 'std::string' : illegal use of this type as an expressionD:\Cyprox Studios\The King Of Gods\QuickCode\main.cpp(359) : error C2059: syntax error : ')'D:\Cyprox Studios\The King Of Gods\QuickCode\main.cpp(360) : error C2275: 'A' : illegal use of this type as an expression D:\Cyprox Studios\The King Of Gods\QuickCode\main.cpp(348) : see declaration of 'A'D:\Cyprox Studios\The King Of Gods\QuickCode\main.cpp(360) : error C2059: syntax error : ')'
Well, that's just it. Compiler is broken.
Anyway, I've come to somewhat esoteric solution.
template <class T> struct TType {};class Factory{public: template <typename T> T* make(TType<T>){ return new T();}};class A{public: void foo(){ std::cout << "A::foo()" << std::endl;}};int main(){ Factory f; f.make(TType<int>()); f.make(TType<std::string>()); f.make(TType<A>())->foo(); return 0;}
It compiles fine and doesn't produce trash. Here is the assembly (debug).
; 358 : Factory f;; 359 : ; 360 : f.make(TType<int>()); mov al, BYTE PTR $T93490[ebp] push eax lea ecx, DWORD PTR _f$[ebp] call ?make@Factory@@QAEPAHU?$TType@H@@@Z ; Factory::make
So... Muira Yoshimoto sliced off his head, walked 8 miles, and defeated a Mongolian horde... by beating them with his head?
Documentation? "We are writing games, we don't have to document anything".