简体   繁体   English

对结构的困惑

[英]Confusion about structs

It's been a while since I have done C++ so bear with me. 我做了C ++已经有一段时间了,所以请耐心等待。 I have the following struct: 我有以下结构:

struct  sPage { U16 _; };
typedef sPage tPage;

But when I try to do: 但是当我尝试做的时候:

tPage pagenumber = 0;

I get the following error: "No suitable constructor exists to convert from int to sPage". 我收到以下错误:“没有合适的构造函数可以从int转换为sPage”。 What am I doing wrong? 我究竟做错了什么?

You forgot the braces while initializing. 初始化时忘了大括号。 Do it like 这样做

tPage pagenumber = { 0 };

You need curly braces to initialize: 你需要大括号来初始化:

tPage pagenumber = {0};

or make your own constructor: 或制作自己的构造函数:

struct  sPage
{
    U16 _;

    sPage(U16 val) : _(val) { }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM