//#define CONSTRUCTOR_CHECKS //#define METHODS_CHECKS //#define ADDITION_CHECKS #define ADDITION_CHECKS2 //#include #include #include #include "StringClass.h" void local1() { StringClass l_Str; // Operator << overloaded twice to take reference or object as parameter cout << "local 1 : ref " << &l_Str; cout << " obj " << l_Str << endl; } void local2() { StringClass l_Str("Test 2"); cout << "local 2 : ref " << &l_Str; cout << " obj " << l_Str << endl; } void local3() { StringClass *l_Str; l_Str = new StringClass(10, '-'); cout << "local 3 : ref " << l_Str; cout << " obj " << *l_Str << endl; delete l_Str; } //StringClass g_StrObj; // calls the parameterless constructor before call of main routine StringClass *g_StrPtr; StringClass *g_StrPtr2; StringClass *g_StrPtr3; char buffer[10]; int main() { /* StringClass g_StrObj; // Ceci fonctionne. Appelle le constructeur sans paramètres. StringClass g_StrObjn(5); // Appelle le constructeur avec un paramètre entier StringClass g_StrObj2; g_StrObj(4); // Appelle l'opérateur surchargé () */ #ifdef CONSTRUCTOR_CHECKS cout << "Contructor test" << endl; cout << "Object test" << endl; g_StrObj = "Object value"; cout << &g_StrObj << endl << endl; cout << g_StrObj << endl << endl; cout << "Pointer test" << endl; g_StrPtr = new StringClass("Pointer value"); // Operator << overloaded twice to take referenc or object as parameter cout << g_StrPtr << endl << endl; cout << *g_StrPtr << endl << endl; delete g_StrPtr; cout << "Copy constructor" << endl; g_StrPtr = new StringClass(g_StrObj); cout << g_StrPtr << endl << endl; cout << "Local routines test:" << endl; local1(); local2(); local3(); cout << "Out stream test" << endl; cout << "cat 1 " << g_StrPtr << endl; cout << g_StrPtr << " cat 2" << endl; cout << "Numeric to String test" << endl; /* !!!! Note Erreur Pb : cause erreur interne compilteur ds math.h dans projet StringClassTst si le constructeur copie StringClass(StringClass& original) est défini. File ³math.h²; Line 185; While compiling ³main.cp² Error: internal error: file CPP.C line 829 */ cout << itos(4682) << endl; cout << itos(10000) << endl; cout << "Concat test:" << endl; (*g_StrPtr) += "added characters" ; cout << g_StrPtr << endl; delete g_StrPtr; // g_StrObj.~StringClass(); #ifndef COPY_CONSTRUCT cout << "Clone test" << endl; g_StrPtr = g_StrObj.clone(); cout << g_StrObj << endl; #endif #endif #ifdef METHODS_CHECKS cout << "Methods test" << endl; g_StrPtr = new StringClass("Methods checks "); cout << "Char : " << (*g_StrPtr)[0] << (*g_StrPtr)[1] << (*g_StrPtr)[2] << endl; for (int idx=0; idx<9; idx++) buffer[idx] = (*g_StrPtr)[idx]; buffer[10] = 0; cout << buffer << " "; cout << g_StrPtr->length() << " " << g_StrPtr->size() << endl; g_StrPtr3 = new StringClass("appended chars"); g_StrPtr->append(g_StrPtr3); cout << g_StrPtr << " : "; cout << g_StrPtr->length() << " " << g_StrPtr->size() << endl; g_StrPtr2 = new StringClass("second value"); cout << g_StrPtr2 << " : "; cout << g_StrPtr2->length() << " " << g_StrPtr2->size() << endl; g_StrPtr2->swap(g_StrPtr3); cout << g_StrPtr2 << " " << g_StrPtr2->length() << endl; cout << g_StrPtr3 << " " << g_StrPtr3->length() << endl; swap(g_StrPtr2, g_StrPtr3); cout << g_StrPtr2 << " " << g_StrPtr2->length() << endl; cout << g_StrPtr3 << " " << g_StrPtr3->length() << endl; delete g_StrPtr; delete g_StrPtr2; delete g_StrPtr3; #endif #ifdef ADDITION_CHECKS cout << "Addition test" << endl; g_StrPtr = new StringClass("ptr_arg 1 "); g_StrPtr2 = new StringClass("ptr_arg 2 "); g_StrPtr3 = new StringClass("ptr_arg 3 "); // cout << (g_StrPtr + g_StrPtr2 + g_StrPtr3) << endl; // cout << (g_StrPtr + g_StrPtr2) << endl; g_StrObj(0); g_StrObjn(11); g_StrObj = "obj_arg 1 "; g_StrObjn.SetString("obj_arg 2 "); cout << g_StrObj << " + " << g_StrObjn << endl; g_StrObj2 = g_StrObj + g_StrObjn; cout << g_StrObj2 << endl; /* !!!! Note Erreur Pb : cause erreur interne compilateur ds math.h dans projet StringClassTst si le constructeur copie StringClass(StringClass& original) est défini. File ³math.h²; Line 185; While compiling ³main.cp² Error: internal error: file CPP.C line 829 */ cout << (g_StrObj + g_StrObjn) << endl; // cout << (g_StrPtr + g_StrObj) << endl; /* !!!! Note Erreur Pb : cause erreur interne compilteur ds math.h dans projet StringClassTst si le constructeur copie StringClass(StringClass& original) est défini. File ³math.h²; Line 185; While compiling ³main.cp² Error: internal error: file CPP.C line 829 */ // cout << (g_StrObj + g_StrPtr) << endl; #ifdef NON_MEMBER if (g_StrObj < g_StrObjn) cout << "StrObj < StrObjn" << endl; #else if (g_StrObj < g_StrPtr2) cout << "StrObj < StrPtr2" << endl; #endif if (g_StrPtr < g_StrPtr2) cout << "StrPtr < StrPtr2" << endl; delete g_StrPtr; delete g_StrPtr2; delete g_StrPtr3; #endif #ifdef ADDITION_CHECKS2 int idxs, idxe; strcpy(buffer, ",/|"); g_StrPtr = new StringClass("Val1,Val2,Val3"); cout << "Substr 4-11: ." << g_StrPtr->substr(4,8) << "." << endl; g_StrPtr2 = new StringClass("Val1,Val2,Val3"); idxs = g_StrPtr->find_first_of(buffer,2); idxs++; idxe = g_StrPtr2->find_first_of(buffer, idxs); cout << "Second elt: " << idxs << "-" << idxe << " " << g_StrPtr2->substr(idxs, idxe-idxs) << endl; delete g_StrPtr; delete g_StrPtr2; #endif // Problem : in the debugger, quit is possible only by killing the debugger // the application blocks and a restart is necessary return EXIT_SUCCESS; }