# HG changeset patch # User arunabha # Date 1271084466 -3600 # Node ID 29cf076edbda3dfcfbd5becf575ff9275bf5ceb9 # Parent c0296ad2454d9ab7896f6f0ed9996e40e4549008 Extending examples for some more good code bad code. diff -r c0296ad2454d -r 29cf076edbda examples/after/example_classes.h --- a/examples/after/example_classes.h Tue Apr 06 21:24:03 2010 +0100 +++ b/examples/after/example_classes.h Mon Apr 12 16:01:06 2010 +0100 @@ -23,3 +23,29 @@ int iA; int iB; }; + + +//Use the keyword "Typename" when using an initialiser that has been Typedef'd inside a class template +// + +template +class list { + public: + typedef unsigned int myType; + myType setSize (unsigned int x, unsigned int y); + }; + +template +inline typename list::myType list::setSize (unsigned int x, unsigned int y){ //This line will NOT throw the error + return (x*y); + }; + + +//use \x to specify the character code directly + +char* literals() + { + char* string = "123\x7e456"; // use \x to specify the character code directly + return string; + } + diff -r c0296ad2454d -r 29cf076edbda examples/before/example_classes.h --- a/examples/before/example_classes.h Tue Apr 06 21:24:03 2010 +0100 +++ b/examples/before/example_classes.h Mon Apr 12 16:01:06 2010 +0100 @@ -23,3 +23,33 @@ int iA; int iB; }; + + +// Correct refenrencing of types defined inside a class Template +// Symptom GCC : Error: Expected initializer before ' (class name)' + +template +class list { + public: + typedef unsigned int myType; + myType setSize (unsigned int x, unsigned int y); + }; + +template +inline list::myType list::setSize (unsigned int x, unsigned int y) //This line will throw the error + + { + return (x*y); + }; + + + +// Need to use \x to specify the character code directly +char* literals() + { + char* string = "123£456"; + + return string; + } + +