在C ++中,“

编程入门 行业动态 更新时间:2024-10-25 08:28:10
本文介绍了在C ++中,“_MOVE_H”有什么特别之处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个像这样的C ++文件

#ifndef _MOVE_H #define _MOVE_H class Move { int x,y; public: Move(int initX = 0,int initY = 0):x(initX),y(initY){} int getX(){return x; } void setX(int newX){x = newX; } int getY(){return y; } void setY(int newY){y = newY; } }; #endif

令我惊讶的是, #ifndef 和 #endif 被编译器忽略(我发现我没有定义 _MOVE_H 其他地方),我有关于缺少定义的各种错误。我认为我做错了,但是当我尝试使用另一个键(如 _MOVE_Ha 时,一切都恢复正常。 _MOVE_H 意味着C ++中有什么特别之处?

我运行的是Ubuntu 10.04,GCC 4.4.3,如果这很重要。

感谢,

解决方案

只需在您的机器上运行/ usr / include / c ++中的grep _MOVE_H

c ++ / 4.5.0 / bits / h:#ifndef _MOVE_H

根据经验,不要使用 _ 或 __ 前缀的(真正的任何东西)保留供内部使用使用 SOMETHING_MOVE_H (通常是公司名称,...)。

我想这是一个新的标题,用于添加将语义移动到c ++ 0x。

I have a C++ file like this

#ifndef _MOVE_H #define _MOVE_H class Move { int x, y; public: Move(int initX = 0, int initY = 0) : x(initX), y(initY) {} int getX() { return x; } void setX(int newX) { x = newX; } int getY() { return y; } void setY(int newY) { y = newY; } }; #endif

And to my amazement, all the code between #ifndef and #endif is simply ignored by the compiler (I swear that I am not defining _MOVE_H anywhere else), and I have all kinds of errors about missing definitions. I was thinking that I did something wrong, but when I try to use another key (like _MOVE_Ha, everything is back to normal. Does _MOVE_H mean something special in C++ ?

I'm running Ubuntu 10.04, GCC 4.4.3, if that matters.

Thanks,

解决方案

just run grep _MOVE_H in /usr/include/c++ on your machine

for me :

c++/4.5.0/bits/move.h:#ifndef _MOVE_H

As a rule of thumb, don't use things (really anything) prefixed by _ or __. It's reserved for internal usage. Use SOMETHING_MOVE_H (usually name of the company, ...).

I guess it's a new header used to add the move semantic to c++0x.

更多推荐

在C ++中,“

本文发布于:2023-07-27 03:04:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219968.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!