C++ 编译问题

sunloverain2 2010-08-12 09:16:22
]
#define ttt int
ttt a;
typedef struct d
{
int x;
int y;
}int_data;
typedef struct c
{
float x;
float y;
} float_data;
#define mytype(tt) tt##_data
mytype(ttt) uu;

会报告这样的错误
Compiling...
main.cpp
F:\AaronLiu\Project\test\main.cpp(25) : error C2146: syntax error : missing ';' before identifier 'uu'
F:\AaronLiu\Project\test\main.cpp(25) : error C2501: 'ttt_data' : missing storage-class or type specifiers
F:\AaronLiu\Project\test\main.cpp(25) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
Creating browse info file...
BSCMAKE: error BK1506 : cannot open file '.\Debug\main.sbr': No such file or directory
Error executing bscmake.exe.

test.exe - 4 error(s), 0 warning(s)
如果将最后一句改为
mytype(int) uu;
就没有错误了
【】
...全文
97 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jim_King_2000 2010-08-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 xy_zhang 的回复:]

把第一句改成
typedef int ttt;
[/Quote]
xy_zhang 2010-08-12
  • 打赏
  • 举报
回复
把第一句改成
typedef int ttt;
yuhuaijun 2010-08-12
  • 打赏
  • 举报
回复
编译过程中会宏进行宏展开, 此时mytype(ttt) 就相当于ttt_data;不是int_data, 而ttt_data未定义,

sunloverain2 2010-08-12
  • 打赏
  • 举报
回复
但是1楼,为什么不是直接将ttt 替换为int然后int来替代tt形成int_data呢?我还是有疑问丫
sunloverain2 2010-08-12
  • 打赏
  • 举报
回复
2楼 的方法也不对,那样还是错误的,

64,649

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧