gnu编译C++11,最好与win32公用代码

这篇博客探讨了如何在GNU编译环境中使用C++11,并确保代码与Win32平台兼容。重点讨论了预编译命令在不同编译器间的差异,特别是tchar相关的处理,强调了理解并适配预编译处理在跨平台开发中的重要性。
摘要由CSDN通过智能技术生成

看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<<"[&#
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值