可能重复:
c ++ 11标准在哪里
我想购买/下载一些东西.首先,我想要官方c ++ 11参考的数字副本和纸质副本.
另外,我想要一本书,它是关注常用c/c ++函数和STL之类的参考文献的总和,比官方参考本身更容易获得.同样适用于纸质和数字版本.我不需要初学者书,只需要参考.这个可能是固执己见,所以随便说出你喜欢哪一个.
我有这个非常简单的函数,我有一些值需要计算,但只需要一次,最好的时间是在编译时.这些值仅在此函数中有效.这是constexpr的好用还是我应该只声明它们是静态const?
ps我知道性能差异是无关紧要的,但我想用"正确"的c ++ 11方式做到这一点.
void MainWindow::UpdateDateTimes()
{
// for some dumb reason DateTime only has add seconds method
// so we have to calculate the seconds per hour and the number of hours
// we do this with static constant values so that the calculations
// only happen once.
static constexpr const int secsPerHour = 60 * 60;
static constexpr const int cdtOffsetHours = -5;
static constexpr const int edtOffsetHours = -4;
static constexpr const int cetOffsetHours = 2;
static …Run Code Online (Sandbox Code Playgroud) 我在Mesa网站的编译/安装页面上完成了所有步骤,并阅读了常见问题解答.您发送给scons进行编译的最终命令会在python脚本中引发错误.这是我的输出.我究竟做错了什么?如果有人使用最新的台面和mingw或VS2012编译了dsa用于台面,那么请分享!
这是我的输出,我没有在很长一段时间内编写python,但看起来地图/字典不包含键/值对.
C:\Downloads\MesaLib-9.1.5\Mesa-9.1.5>scons platform=windows toolchain=crossming
w machine=x86_64 mesagdi libgl-gdi
scons: Reading SConscript files ...
KeyError: 'CCVERSION':
File "C:\Downloads\MesaLib-9.1.5\Mesa-9.1.5\SConstruct", line 40:
ENV = os.environ,
File "C:\Python27\scons-2.3.0\SCons\Environment.py", line 1002:
apply_tools(self, tools, toolpath)
File "C:\Python27\scons-2.3.0\SCons\Environment.py", line 106:
env.Tool(tool)
File "C:\Python27\scons-2.3.0\SCons\Environment.py", line 1786:
tool(self)
File "C:\Python27\scons-2.3.0\SCons\Tool\__init__.py", line 183:
self.generate(env, *args, **kw)
File "C:\Downloads\MesaLib-9.1.5\Mesa-9.1.5\scons\gallium.py", line 313:
ccversion = env['CCVERSION']
File "C:\Python27\scons-2.3.0\SCons\Environment.py", line 412:
return self._dict[key]
Run Code Online (Sandbox Code Playgroud) 是否有跨平台方式来检测调试模式编译?如果没有,那么如何为顶级编译器做到这一点; MSVC,GNU&MINGW,mac,clang,intel.
例如,MSVC可以检测调试模式,如下所示.
#if defined _DEBUG
// debug related stuff here
#else
// release related stuff here
#endif
Run Code Online (Sandbox Code Playgroud) 我正在编写自己的字符串类,仅仅是为了学习和巩固一些知识.我有一切工作,除了我想有一个使用移动语义与std :: string的构造函数.
在我的构造函数中,我需要复制并清空std :: string数据指针和其他东西,它需要保留为空但有效的状态,而不删除字符串指向的数据,我该怎么做?
到目前为止,我有这个
class String
{
private:
char* mpData;
unsigned int mLength;
public:
String( std::string&& str)
:mpData(nullptr), mLength(0)
{
// need to copy the memory pointer from std::string to this->mpData
// need to null out the std::string memory pointer
//str.clear(); // can't use clear because it deletes the memory
}
~String()
{
delete[] mpData;
mLength = 0;
}
Run Code Online (Sandbox Code Playgroud) c++ stdstring dynamic-memory-allocation move-semantics c++11
使用c#我有一个列表,这些对象都有一个浮动质量,在创建对象时随机化.
什么是循环列表并找到质量最高的对象的最有效方法?
所以这是一个例子.恒星的mLocation和mSpeed是一个Vector3自定义类型.
我试过了:
Star &star = *iStar;
Star star = *iStar;
Run Code Online (Sandbox Code Playgroud)
iStar->直接使用不适合我的操作员,不知道为什么.那么这样做的正确方法是什么?
void UniverseManager::ApplySpeedVector()
{
std::list <Star>::const_iterator iStar;
for (iStar = mStars.begin(); iStar != mStars.end(); ++iStar)
{
// how to I get a hold on the object the iterator is pointing to so I can modify its values
// i tried Star &star = *iStar; this is illegal
// tried just using the iStar->mLocation += iStar->mSpeed this also fails due to the operator not …Run Code Online (Sandbox Code Playgroud) 可能重复:
C++将int和string转换为char*
你好,我正在制作游戏,我有一个记分板.得分存储在一个int变量中,但是我用于游戏的库需要一组字符,用于为我的记分板输出文本.
那么如何将int转换为字符数组呢?
int score = 1234; // this stores the current score
dbText( 100,100, need_the_score_here_but_has_to_be_a_char_array);
// this function takes in X, Y cords and the text to output via a char array
Run Code Online (Sandbox Code Playgroud)
我正在使用的库是DarkGDK.
tyvm :)
我正在谈论的类型显示在第3页:http: //dl.dropbox.com/u/13100941/C%2B%2B11.pdf
int8_t uint8_t int16_t uint16_t int32_t uint32_t int64_t uint64_t
我正在使用Visual Studio 2012.如果GNU/Mingw的不同之处包括如何在这些编译器上获取它们.
我正在做一个简单的Random课:
class Random
{
public:
static bool seeded = false;
static void SeedRandom( int number )
{
srand(number);
}
static int GetRandom(int low, int high)
{
if ( !seeded )
{
srand ((int)time(NULL));
}
return (rand() % (high - low)) + low;
}
};
Run Code Online (Sandbox Code Playgroud)
显然,C++不允许将整个类声明为static(这使得在C#中这么容易).我把所有的成员都改成了static.也没有static构造函数所以我没有办法初始化我,bool seeded除非我手动调用函数,这违背了目的.我可以改为使用常规构造函数,我必须在其中创建一个Random我不想做的实例.
另外,有没有人知道新的C++ 0x标准是否允许静态类和/或静态构造函数?
除了显而易见的答案之外,为什么要这么说呢?另外我怎么解决这个问题,我不想在这个项目中添加c ++ 11代码.
#include <random>
Run Code Online (Sandbox Code Playgroud)
mingw 4.4(QTSDK附带的版本,不使用QT库,只是QT Creator)
此文件需要编译器和库支持即将推出的\ ISO C++标准,C++ 0x.此支持目前是实验性的,必须使用-std = c ++ 0x或-std = gnu ++ 0x编译器选项来启用.