yawnobleix yawnobleix - 1 year ago 99
C++ Question

Confusion about structs

It's been a while since I have done C++ so bear with me. 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". What am I doing wrong?

Answer Source

You need curly braces to initialize:

tPage pagenumber = {0};

or make your own constructor:

struct  sPage
    U16 _;

    sPage(U16 val) : _(val) { }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download