g ++ -Wall选项包括-Wreorder.该选项的作用如下所述.我不清楚为什么有人会关心(特别是在-Wall中默认打开它).
-Wreorder (C++ only)
Warn when the order of member initializers given in the code does not
match the order in which they must be executed. For instance:
struct A {
int i;
int j;
A(): j (0), i (1) { }
};
The compiler will rearrange the member initializers for i and j to
match the declaration order of the members, emit-ting a warning to that
effect. This warning is enabled by -Wall.
#ifndef __TEST__
#define __TEST__
namespace std
{
template<typename T>
class list;
}
template<typename T>
void Pop(std::list<T> * l)
{
while(!l->empty())
l->pop();
}
#endif
Run Code Online (Sandbox Code Playgroud)
并在我的主要使用该功能.我收到错误.当然,我知道有更多的模板参数std::list(我认为是分配器).但是,这是不重要的.我是否必须知道模板类的完整模板声明才能转发声明它?
编辑:我之前没有使用指针 - 这是一个参考.我会用指针试一试.
这张便条说:
-ansi:告诉编译器实现ANSI语言选项.这会关闭GCC的某些与ANSI标准不兼容的"功能".
-pedantic:与-ansi此结合使用,这告诉编译器严格遵守ANSI标准,拒绝任何不符合的代码.
首先要做的事情:
-pedantic和-ansi选项的目的是什么(我无法理解上面的描述)?通常在C下gcc,我将从以下一组警告标志开始(从多个来源痛苦地组装):
-Wall -Wextra -Wformat-nonliteral -Wcast-align -Wpointer-arith -Wbad-function-cast \
-Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Winline -Wundef \
-Wnested-externs -Wcast-qual -Wshadow -Wwrite-strings -Wno-unused-parameter \
-Wfloat-equal -pedantic -ansi
Run Code Online (Sandbox Code Playgroud)
我将使用这组警告构建(至少我的调试版本)并修复我可能做的所有事情(通常是一切),然后只删除标记,如果它们不相关或不可修复(几乎从不这样).有时,-Werror如果我必须在编译时离开,我也会添加.
我只是拿起C++(是的,我落后了15年),我想从右脚开始.
我的问题是:是否有人为C++预先编译了类似的完整警告标志集g++?(我知道其中很多都是一样的.)
我在Mac OSX Mountain Lion上使用http://hpc.sourceforge.net上的gcc 4.8.1 .我正在尝试编译一个使用该to_string函数的C++程序<string>.我-std=c++11每次都需要使用旗帜:
g++ -std=c++11 -o testcode1 code1.cpp
Run Code Online (Sandbox Code Playgroud)
有没有办法默认包含这个标志?
我有一个成员函数,定义如下:
Value JSONDeserializer::ParseValue(TDR type, const json_string& valueString);
Run Code Online (Sandbox Code Playgroud)
当我编译源代码时,我得到:
错误:成员'ParseValue'上的额外限定'JSONDeserializer ::'
这是什么?如何删除此错误?
我从读codeforces博客,如果我们#include <bits/stdc++.h>在一个C++程序那么就没有必要包括任何其他的头文件.如何#include <bits/stdc++.h>工作,是否可以使用它而不是包括单独的头文件?
我最近有一个课程项目,我必须用G ++制作一个程序.我使用了一个makefile,由于某种原因,它偶尔会留下一个.h.gch文件.有时,这不会影响编译,但是每次都会导致编译器针对已修复或没有意义的问题发出错误.我有两个问题:
1)什么是.h.gch文件以及用于什么?和
2)为什么没有清理时会引起这样的问题?
谢谢您的帮助.
以下代码适用于Visual Studio 2008,有无优化.但它只适用于没有优化的G ++(O0).
#include <cstdlib>
#include <iostream>
#include <cmath>
double round(double v, double digit)
{
double pow = std::pow(10.0, digit);
double t = v * pow;
//std::cout << "t:" << t << std::endl;
double r = std::floor(t + 0.5);
//std::cout << "r:" << r << std::endl;
return r / pow;
}
int main(int argc, char *argv[])
{
std::cout << round(4.45, 1) << std::endl;
std::cout << round(4.55, 1) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
输出应该是:
4.5
4.6
Run Code Online (Sandbox Code Playgroud)
但是带有优化(O1- O3)的g ++ …
我一直在研究朋友编写的一些C++代码,并且我在使用gcc4.6编译时遇到了以前从未见过的错误:
error: use of deleted function
‘GameFSM_<std::array<C, 2ul> >::hdealt::hdealt()’ is implicitly deleted because the default definition would be ill-formed:
uninitialized non-static const member ‘const h_t FlopPokerGameFSM_<std::array<C, 2ul> >::hdealt::h’
Run Code Online (Sandbox Code Playgroud)
编辑:这来自使用boost MSM:Boost网页的部分代码
Edit2:= delete()源代码中没有任何地方使用过.
一般来说,这个错误意味着什么?发生此类错误时,我应该寻找什么?