I am very new at c++ programming and i must admit that i never take up with any kind of programming language, that means that i am a completely noob at programming!
My first question is does using namespace std; should be placed right after when we actually need it or should be places after the header file declaration?
My second question is i am trying to learn about *this hidden pointer and it is very confusing to me, so could you explain more clear as possible, because in addition to http://www.learncpp.com/ i find tutorial on youtube too about *this pointer and even so is somewhat confusing to me, what do you thing? Here is the video http://www.youtube.com/watch?v=o2t5CO2KTug
For my first question i am sure that the right coding, is to place it when we need it, that is at least what i am learned with tutorials on this site.
the usingnamespace std; declaration is conventionally placed after your list of header files just before main(), but you can place it at any scope and then it will only be valid at that scope, and hence any classes you use within that scope will be searched for within the std namespace.
Regarding the this keyword, in simple terms it allows you to access members (via a pointer, called 'this') of an object belonging to the class, whilst within the scope of that class. The reason you need 'this' is because the class is yet to be instantiated and hence there is no object to refer to if you need to access its members to implement part of the class.
there's no real need in the this keyword in that function, it could just as well be x =dArg;
An example of when you might need to use the this pointer is when an object wants to pass itself into a function from inside of one of it's own member functions, the object would dereference the this pointer *this to pass in the object itself
in your example, I think you are right that the answer will depend on whether you use the this keyword or not.
The reason is, is that without the this keyword, without a full qualification of the double x that is local to CMyClass::Set the default scope will be the local scope and hence x= dArg. However, since this x and dArg are local to CMyClass::Set then they wont exist after exiting the function and CMyClass::x remains equal to its member list initialised value of 2.0.
However, with the this keyword you are referring to CMyClass::x rather than the x local to CMyClass::Set and hence CMyClass::x = dArg after calling CMyClass::Set, rather than 2.0.
So yes, if you declare variables local to member functions within a class which has data members of the same name then the this keyword will matter. However, you probably shouldn't do this and if you don't then you wouldn't need the this keyword in this case.