Created
January 20, 2017 14:53
-
-
Save keisukeYamagishi/348d434db0b93b10c2773f5be8acf2c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "stu.h" | |
int main() { | |
char* ch = "Call"; | |
name1::name2::name3::stu::getInstance()->call(10,ch, [=](int num, char* ch){ | |
printf("num ++ >> %d char ** > %s",num,ch); | |
}); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stu.h" | |
#include <iostream> | |
namespace name1{ | |
namespace name2{ | |
namespace name3{ | |
static stu* stu1 = NULL; | |
stu * stu::getInstance() { | |
if(stu1==NULL){ | |
stu1 = new stu; | |
} | |
return stu1; | |
} | |
void stu::call(int num, const char *ch, const CallBackFunction &call){ | |
std::cout << "num >> " << num << "char :: > " << ch << std::endl; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by shichimi on 2016/12/05. | |
// | |
#ifndef STUDY_STU_H | |
#define STUDY_STU_H | |
#include <functional> | |
namespace name1{ | |
namespace name2{ | |
namespace name3{ | |
class stu { | |
public: | |
static stu * getInstance(); | |
typedef std::function<void(int num, char* ch)> CallBackFunction; | |
void call(int num, const char *ch, const CallBackFunction &call); | |
}; | |
} | |
} | |
} | |
#endif //STUDY_STU_H |
compile:
c++ -std=c++11 main.cpp stu.cpp -o stu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
C++ study