s i s t e m a o p e r a c i o n a l m a g n u x l i n u x | ~/ · documentação · suporte · sobre |
Next
Previous
Contents
7. Renaming the String class
7.1 Case 1: Simple renameIf you do not like the String class name then you can use "typedef" to rename the String class. In all the files where you do include String.h, insert these lines: // If you do not like the class name String, then you can rename using typedef typedef String StringSomethingElseIwant; // Your remaing code may be like this .... int main() { StringSomethingElseIwant aa_renstr; aa_renstr = "I renamed the String Class using typedef"; .......etc... } See the example_String.cpp. 7.2 Case 2: Resolve conflictIf there is a conflict with another class-name having the same name, and you want to use both this class and conflicting class then you use this technique - in all the files where you do include String.h, insert these lines: #define String String_somethingelse_which_I_want #include "String.h" #undef String #include "ConflictingString.h" // This also has String class... // All your code goes here... main() { String_somethingelse_which_I_want aa; String bb; // This string class from conflicting string class aa = " some sample string"; bb = " another string abraka-dabraka"; ....... } The pre-processor will replace all literals of String to "String_somethingelse_which_I_want" and immdiately undefines String. After undef the conflicting string class header file is included which defines the "String" class. Next Previous Contents |