#include <iostream>
#include <typeinfo>
#include <stdio.h>
using namespace std;
enum EM {ONE, TWO};
void func(int i) {
cout << __PRETTY_FUNCTION__ << endl;
}
void func(EM i) {
cout << __PRETTY_FUNCTION__ << endl;
}
////////////////////////////////////////////////////
template <typename T>
void trait(T t) {
cout << __PRETTY_FUNCTION__ << endl;
}
template <typename R, typename C, typename Arg1>
void trait_detail(R (C::*class_member_pointer)(Arg1)) {
cout << __PRETTY_FUNCTION__ << endl;
}
////////////////////////////////////////////////////
class A {
public:
virtual void func() {
cout << __PRETTY_FUNCTION__ << endl;
}
virtual A& reflect() {
cout << __PRETTY_FUNCTION__ << endl;
return *this;
}
};
A* func_provide_local_class(int x = 0) {
class LocalA: public A {
public:
LocalA(int x): m_x(x) {};
virtual void func() {
cout << __PRETTY_FUNCTION__ << endl;
}
virtual A& reflect() {
return *this;
}
private:
int m_x;
};
A* pa = new LocalA(x);
cout << typeid(pa).name() << endl;
return pa;
}
////////////////////////////////////////////////////
class B {
public:
virtual int func(double& d) = 0;
};
////////////////////////////////////////////////////
int main(int argc, char* argv[]) {
//enum is also a specific type
EM em = ONE;
func(argc);
func(em);
trait(em);
printf("--------------------------------------------\n");
//trait in two ways
trait(&B::func);
trait_detail(&B::func);
printf("--------------------------------------------\n");
//trial for local class, for more information see as http://www.geeksforgeeks.org/local-class-in-c/ and http://www.cppblog.com/mzty/archive/2007/05/24/24766.html
A* pa = func_provide_local_class();
pa->func();
printf("--------------------------------------------\n");
//there's no way to use local class externally
trait(pa);
trait(pa->reflect());
printf("--------------------------------------------\n");
return 0;
}
=================== run result ====================
void func(int)
void func(EM)
void trait(T) [with T = EM]
--------------------------------------------
void trait(T) [with T = int (B::*)(double&)]
void trait_detail(R (C::*)(Arg1)) [with R = int, C = B, Arg1 = double&]
--------------------------------------------
P1A
virtual void func_provide_local_class(int)::LocalA::func()
--------------------------------------------
void trait(T) [with T = A*]
void trait(T) [with T = A]
--------------------------------------------