【问题标题】:C++ header guards won't compileC++ 标头保护不会编译
【发布时间】:2011-10-23 18:36:21
【问题描述】:

在 vs 2010 中无法使用标头保护来编译任何代码。例如:

#ifndef SIMPLE.H
#define SIMPLE.H

#include <iostream>

class Place {
private:
int m_xplace;
int m_yplace;
Place(){}
public:
Place(int x, int y) : m_xplace(x), m_yplace(y) {}
void Move(int x, int y);
void set_place(int x, int y) {m_xplace = x, m_yplace = y;}
int get_place_x() {return m_xplace;}
int get_place_y() {return m_yplace;}
};
#endif

我从编译器得到这个输出:

1>------ Build started: Project: 1, Configuration: Release Win32 ------
1>e:\projects\1\1\simple.h(1): warning C4067: unexpected tokens following preprocessor     directive - expected a newline
1>e:\projects\1\1\simple.h(2): error C2008: '.' : unexpected in macro definition
1>e:\projects\1\1\simple.h(1): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>e:\projects\1\1\simple.h(2): error C2008: '.' : unexpected in macro definition
========== 
Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我在这里遗漏了一些明显的东西吗?我很确定我的语法正确。谢谢。

【问题讨论】:

    标签: c++ visual-studio-2010 compiler-errors compiler-warnings


    【解决方案1】:

    您不能在标识符中使用.

    试试这个:

    #ifndef SIMPLE_H
    #define SIMPLE_H
    

    【讨论】:

    • 现在我回头看,输出很清楚哪里出了问题。
    • 是的,它发生了。我也经常忽略一些事情,并开始在错误的地方寻找错误(比如代码本身)。
    猜你喜欢
    • 2015-10-08
    • 1970-01-01
    • 2011-06-13
    • 2020-04-30
    • 2013-11-13
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 2013-11-17
    相关资源
    最近更新 更多