Skip to content

Latest commit

 

History

History
111 lines (62 loc) · 5.13 KB

File metadata and controls

111 lines (62 loc) · 5.13 KB

 

 

 

 

 

 

C++11STLQt CreatorLubuntu

 

member function example 2: pointer to member functions is a member function example.

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

  • STL STL: GNU ISO C++ Library, version 4.9.2

 

 

 

 

 

Qt project file: ./CppMemberFunctionExample2/CppMemberFunctionExample2.pro

 


TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += main.cpp # # # Type of compile # # CONFIG(release, debug|release) {   DEFINES += NDEBUG NTRACE_BILDERBIKKEL } QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++ unix {   QMAKE_CXXFLAGS += -Werror }

 

 

 

 

 

./CppMemberFunctionExample2/main.cpp

 


#include <iostream> void SayA() { std::cout << "A\n"; } void SayB() { std::cout << "B\n"; } struct Person {   void SayBye() const noexcept { std::cout << "Bye\n"; }   void SayHello() const noexcept { std::cout << "Hello\n"; } }; int main() {   //Ordinay pointer to functions   {     typedef void (*Function)();     const Function a = SayA;     const Function b = SayB;     a();     b();     Function c = SayA;     c();     c = SayB;     c();   }   //Pointer to member functions   {     typedef void (Person::*MemberFunction)() const; //Note: do not add noexcept     const Person p;     const MemberFunction a = &Person::SayHello;     ((&p)->*a)();     const MemberFunction b = &Person::SayBye;     ((&p)->*b)();     MemberFunction c = &Person::SayHello;     ((&p)->*c)();     c = &Person::SayBye;     ((&p)->*c)();   } } /* Screen output A B A B Hello Bye Hello Bye Press <RETURN> to close this window... */