游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1805|回复: 1

typedef struct constructor

[复制链接]

414

主题

611

帖子

621

积分

高级会员

Rank: 4

积分
621
发表于 2009-6-14 00:41:00 | 显示全部楼层 |阅读模式
typedef struct constructor??霈Ferror C4430的??,???一下有?法修正??


  1. struct b
  2. {

  3.      b()
  4.      {

  5.      }

  6.      b(int p1)
  7.      {
  8.      m_p1=p1;
  9.      }

  10.      int m_p1;
  11. };

  12. typedef struct
  13. {

  14.      a()
  15.      {

  16.      }

  17.      a(int p1)
  18.      {
  19.      m_p1=p1;
  20.      }

  21.      int m_p1;
  22. }a;

  23. //?? 1 error C4430: ?漏型?e??- 假???nt。注意: C++ 不支援default-int
复制代码

2

主题

19

帖子

19

积分

新手上路

Rank: 1

积分
19
发表于 2009-6-14 22:49:00 | 显示全部楼层

Re:typedef struct constructor

这里的a不是这个struct的名字,所以不能使用名为a的构造函数,实际上你还没有确定这个struct的名字
如果需要使用构造函数要这样用:
typedef struct a // <-取个名字
{
    a()
    { }
    ....
} a_t;
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-19 23:38

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表