请教一个C/C++语法编译不通过问题

cokeliu 2012-02-08 06:30:53
请教一个C++/C的语法编译问题. 我在VC6中一个头文件中
typedef struct SDP_ServiceEntry_t
{
BT_StackConfig_t* Stack;
const uint8_t TotalTableAttributes;
const SDP_ServiceAttributeTable_t* AttributeTable;
struct SDP_ServiceEntry_t* NextService;
}

一个CPP文件中定义一个全局变量
SDP_ServiceEntry_t ServiceEntry_RFCOMMSerialPort;

编译报错:
error C2512: 'SDP_ServiceEntry_t' : no appropriate default constructor available
...全文
56 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eleven 2012-02-08
  • 打赏
  • 举报
回复
你的结构体中定义一个构造函数把常量成员初始化一下。
alexander_david 2012-02-08
  • 打赏
  • 举报
回复
常量结构成员必须在构造的时候初始化。
alexander_david 2012-02-08
  • 打赏
  • 举报
回复
typedef struct SDP_t
{
int a;
const int b;
public:
SDP_t();
}SDP;

SDP_t::SDP_t():b(100)
{
}

这样就可以了。
可以参考这个网页:http://wenku.baidu.com/view/3525bebf960590c69ec3760f.html
meat 2012-02-08
  • 打赏
  • 举报
回复
有参数的构造函数??
SDP_ServiceEntry_t ServiceEntry_RFCOMMSerialPort(??);
void 或参数

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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