What is the difference between “::” “.” and “->” in c++ [duplicate]

1.-> for accessing object member variables and methods via pointer to object Foo *foo = new Foo(); foo->member_var = 10; foo->member_func(); 2.. for accessing object member variables and methods via object instance Foo foo; foo.member_var = 10; foo.member_func(); 3.:: for accessing static variables and methods of a class/struct or namespace. It can also be used … Read more

C++ callback using class member

Instead of having static methods and passing around a pointer to the class instance, you could use functionality in the new C++11 standard: std::function and std::bind: #include <functional> class EventHandler { public: void addHandler(std::function<void(int)> callback) { cout << “Handler added…” << endl; // Let’s pretend an event just occured callback(1); } }; The addHandler method … Read more

php static function

In the first class, sayHi() is actually an instance method which you are calling as a static method and you get away with it because sayHi() never refers to $this. Static functions are associated with the class, not an instance of the class. As such, $this is not available from a static context ($this isn’t … Read more

Static nested class in Java, why?

The Sun page you link to has some key differences between the two: A nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the enclosing class, even if they are declared private. Static nested classes do not have access to other members of the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)