C++标头防护无法编译

发布于 2024-12-11 14:44:16 字数 1068 浏览 0 评论 0原文

无法使用标头防护获取任何代码在 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 ==========

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

Can't get any code using header guards to compile in vs 2010. For example:

#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

I get this output from compiler:

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 ==========

Am i missing something obvious here? I'm quite sure i have the syntax correct. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假装不在乎 2024-12-18 14:44:16

您不能在标识符中使用 .

试试这个:

#ifndef SIMPLE_H
#define SIMPLE_H

You can't use . in the identifier.

Try this instead:

#ifndef SIMPLE_H
#define SIMPLE_H
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文