Convert Blitzcode to C++?
Blitz3D Forums/Blitz3D Beginners Area/Convert Blitzcode to C++?
| ||
I have a Blitz project that I'd like to transfer to C++ with Irrlicht. Is there a chart showing C++ equivalent algorithms to Blitz code (at least the non-graphics part)? For example, the type declaration: Type Typename Field stuff1 Field stuff2 End Type seems to be similar to the C++ equivalent: class Typename { public: Typename(); //Constructor for initializing stuff1 and stuff2 in new instances of Typename int stuff1; //Assumed int int stuff2; //Assumed int }; std::list< Typename > listOfTypenameInstances; So, then, the Blitz code: pType.Typename = New Typename seems to be equivalent to the C++ equivalent: Typename tempVar; listOfTypenameInstances.push_back( tempVar ); Typename *pType = &listOfTypenameInstances.back(); And then, the Blitz code: pType\stuff1 = 101 seems to be equivalent to the C++ code: pType->stuff1 = 101; |
| ||
Here's a suggestion: instead of making the list a global, why not make it a private static member of that class. If other classes need access to that list, use a public, static accessor function for that: In the .h header: #include blablabla class Typename { public: explicit Typename( int stuff1, int stuff2 ); inline static std::list< Typename >* getTypenameList() { return s_typenameList; } private: static std::list< Typename >* s_typenameList; int m_stuff1; int m_stuff2; };In the .cpp implementation: std::list< Typename >* Typename::s_typenameList = new std::list< Typename > Typename::Typename( int stuff1, int stuff2 ) : m_stuff1( stuff1 ) , m_stuff2( stuff2 ) { s_typenameList.push_back( this ); // Add itself into its list, automatically. } // It then becomes... Typename* me = new Typename(); std::list< Typename >* list = me->getTypenameList(); // list->front() == *me;It's been a while since I last played with C++ so there might be a syntax error somewhere. |
| ||
I like it. |
| ||
Unless it's a requirement to use C++, doing the same Blitz3D-like behaviour in BlitzMax would require much less code.Type Typename Method New() typenameList.AddLast( Self ) End Method Function getList:TList() 'Considered a "static" function. Return typenameList End Function Global typenameList:TList = New TList 'Considered a "static" member. End Type Local obj1:Typename = New Typename Local obj2:Typename = New Typename Print( Typename.getList().Count() ) 'Prints '2'. |
| ||
C++ is a requirement. |