VC++ 2005 Express の cl.exe (VC8?) だと通るこのコードが、 cygwin の gcc 3.4.4 ではエラーになりました。 > 2: error: declaration of `S*T::S' > 1: error: changes meaning of `S' from `typedef struct S S'
>>350 template < class T > class CMaterial { CMaterial* NextMaterial; public: T* CreateNext() { return NextMaterial = new T; } }; class CBlock : public CMaterial<CBlock> {};
/* または */
class CMaterial { CMaterial* NextMaterial; protected: virtual CMaterial* Factory() const { return new CMaterial; } public: CMaterial* CreateNext() { return NextMaterial = Factory(); } }; class CBlock : public CMaterial<CBlock> { protected: virtual CMaterial* Factory() const { return new CBlock; } };
class Base{}; class Advance : public Base {}; // 戻り値なし・引数ありパターン void createv( Base* &rp_a ){ rp_a = new Advance; } // 戻り値あり・引数なしパターン Base* createb(){ return ( new Advance ); }
#include <iostream.h> #include <malloc.h> struct KATA{ int ab; int cd; }; int MyFunction(int x, struct KATA *y) { y = (struct KATA *)calloc(x, sizeof(struct KATA)); if(y == NULL){ return(1); }
for(int i = 0;i <= x -1;i++){ y[i].ab = 2; y[i].cd = 3; }
So if one's compiler's documentation happens to say anywhere that main may have the return type void then main may indeed have the return type void and a program with void main() is a conforming program.