   using the same variable name twice in C++
  in java code u can have two variables with the same nameegclass b{ String name ="";public void method(String name){   this.name = name;}}is there a way u can do this in c++. That exact code in C++ generates an error request for member y in this   
  You can, but it isn't a good idea. This is referred to as shadowing a variable, and is very prone to causing confusing bugs.   ;  You don't actually have two variables of the same name in that snippet.  You have a variable B::name and a local variable (arg to function) called name.  The exact same construct is possible in C++.  The reason you got an error is because you tried to compile Java code with a C++ compiler.You could do this:class B{public:   char *name;   void SetName(char *name) { this->name = name; }};;  hehe u never know it may work lol they teach us bad practices at universit that sucks   