问题:

我一直玩clang一段时间,我偶然发现了“test / SemaTemplate / dependent-template-recover.cpp”(在clang发行版中),它应该提供从模板错误中恢复的提示。

整个过程可以很容易地删除到一个最小的例子:

template<typename T, typename U, int N> struct X {
    void f(T* t)
    {
        // expected-error{{use 'template' keyword to treat 'f0' as a dependent template name}}
        t->f0<U>();
    }
};

clang产生的错误消息:

tpl.cpp:6:13: error: use 'template' keyword to treat 'f0' as a dependent template name
         t->f0<U>();
            ^
            template 
1 error generated.

…但是我很难理解究竟应该在哪里插入template关键字以使代码在语法上正确?

I’ve been playing with clang a while, and I stumbled upon “test/SemaTemplate/dependent-template-recover.cpp” (in the clang distribution) which is supposed to provide hints to recover from a template error.The whole thing can be easily stripped down to a minimal example:The error message yielded by clang:… But I have a hard time understanding where exactly one is supposed to insert the template keyword to have the code to be syntactically correct?

问题:

当我尝试在Win32或x64模式下使用Visual Studio 2010编译我的c ++项目时,我收到以下错误:

>C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\include\\winnt.h(135): fatal error C1189: #error : "No Target Architecture"

我的预处理器定义说WIN32; _DEBUG; _CONSOLE;%(PreprocessorDefinitions)

导致此错误的原因是什么?如何解决?

// winnt.h: lines 127-136, MSVS says this is an inactive preprocessor block
#if defined(_WIN64)

#if defined(_AMD64_)
#define PROBE_ALIGNMENT( _s ) TYPE_ALIGNMENT( DWORD )
#elif defined(_IA64_)
#define PROBE_ALIGNMENT( _s ) (TYPE_ALIGNMENT( _s ) > TYPE_ALIGNMENT( DWORD ) ? \
                              TYPE_ALIGNMENT( _s ) : TYPE_ALIGNMENT( DWORD ))
#else
#error "No Target Architecture"
#endif

更新:我创建了一个新的msvs项目并将我的代码复制到它。 我不再有error : "No Target Architecture" ,但现在我有一堆涉及winnt.h和winbase.h的编译错误,并且没有涉及我的任何文件的编译错误。 这些文件是否可能已损坏? 我需要重新安装MSVS 2010吗?

更新2:所以我缩小了我的问题,发现它是#include <WinDef.h>导致我的所有编译错误与winnt.h但我仍然不知道如何解决它。

When I try to compile my c++ project using Visual Studio 2010 in either Win32 or x64 mode I get the following error:My preprocessor definitions say WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)What is causing this error and how do I fix it?Update: I created a new msvs project and copied my code to it.I no longer have error : "No Target Architecture" , but now I have a bunch of compile errors involving winnt.h and winbase.h and no compile errors involving any of my files.Is it possible these files are corrupted?Do I need to reinstall MSVS 2010?Update 2: So I narrowed down my problem and found that it is #include <WinDef.h> that is causing all of my compile errors with winnt.h but I still don’t know how to fix it.

问题:

我正在将代码从Linux C移植到Visual C ++ for windows。

Visual C ++不知道#include <stdint.h>所以我评论了它。

后来,我发现了很多'uint32_t': identifier not found错误。 怎么解决?

I’m porting code from Linux C to Visual C++ for windows.Visual C++ doesn’t know #include <stdint.h> so I commented it out.Later, I found a lot of those 'uint32_t': identifier not found errors.How can it be solved?

问题:

我收到此错误消息,代码如下:

class Money {
public:
    Money(float amount, int moneyType);
    string asString(bool shortVersion=true);
private:
    float amount;
    int moneyType;
};

首先,我认为默认参数不允许作为C ++中的第一个参数,但允许使用。

I’m getting this error message with the code below:First I thought that default parameters are not allowed as a first parameter in C++ but it is allowed.

问题:

我正在尝试使用g++-std=c++11c++0x标志进行编译。

但是,我收到此错误

cc1plus: error: unrecognized command line option "-std=c++11"

g ++ –version

g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I’m trying to compile using g++ and either the -std=c++11 or c++0x flags.However, I get this errorg++ –version