0 Members and 2 Guests are viewing this topic.
class user{private $fname;private $lname;public function get($var){return $this->$var;}};
class user{ private: string name; public: user(string x){ this->name=x;} string get(string vaar){ return this->vaar; }};
You get an error, because you use this-> to reference a local (function) variable, where this-> is used for class members, so the program cannot find the variable vaar (which is a local, not class, variable) in a class and throws an error.
return vaar;
TL;DR: It doesnt work because C++ Isn't PHP.
Heres the (more) technical answer, C++ doesn't look inside variables and act the way you want it too.this->vaar always means this->vaar, no matter the contents of vaar. It never changes and means this->name, not in C++ at least.It will not work because C++ and PHP handle this differently, because they may share some syntax but they are different languages.If you want more of an answer join ##C++ on Freenode and ask but I doubt they will be gentle.