看makefile:
#jingz's first file to test makeFile
allTarget:stdafx_target 11_12_target
g++ stdafx.o functor-adapter_p431.o -o functor-adapter_p431.exe
#remove the object files
rm -rf stdafx.o functor-adapter_p431.o
#complie the cpps into objects
stdafx_target:
g++ -std=c++11 -c stdafx.cpp -o stdafx.o
11_12_target:
g++ -std=c++11 -c functor-adapter_p431.cpp -o functor-adapter_p431.o
平时使用vs、xcode等ide,老是忽略预编译命令,还是得吃
-std=c++11 C++11的预编译定义,因为gnu默认关闭C++11特性
比较多家的编译器是有所区别的,根据实际情况使用预编译处理。
1)比如tchar相关:
#ifdef WIN32
#include "targetver.h"
#include <tchar.h>
#endif
如果是cocos2dx,则可以使用 CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 这类似预编译定义处理跨平台的兼容问题
// functor-adapter_p431.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <algorithm>//元素操作算法
#include <functional> //函数配接器,bind、compose、negate
#include <iostream>
#include <iterator>
#include <vector>
#include <memory>
using std::cout;
using std::cin;
using std::endl;
bool print(int i)
{
std::cout<< i << " ";
return true;
}
class Int
{
public:
explicit Int(int i):m_i(i){};
~Int(void){};
void print1(void) const
{
cout<<"["<<m_i<<"]";
}
void print2(Int &i)const
{
cout<<"[&#