f



struct with const member variable without explicit constructor

Hi.

Is the following code c++:

   typedef struct {
       int a;
       int const b;
   } C;

The Intel compiler gives the following warning message:
warning #411: class "C" defines no constructor to initialize the
following:

             const member "C::b"

But it is possible to initialize b with the old C-style:

C c = { 1, 2 };


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
chb
2/2/2011 7:39:18 AM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8506) is leader. Post Follow

2 Replies
1566 Views

Similar Articles

[PageSpeed] 39

On 2011-02-02 14:39, chb wrote:
> 
> Is the following code c++:
> 
>    typedef struct {
>        int a;
>        int const b;
>    } C;

Yes, this is well-formed C++.

> The Intel compiler gives the following warning message:
> warning #411: class "C" defines no constructor to initialize the
> following:
> 
>              const member "C::b"
> 
> But it is possible to initialize b with the old C-style:
> 
> C c = { 1, 2 };

Your example is reasonable but note that compilers are free to
diagnose anything - even well-formed and well-defined code.

HTH & Greetings from Bremen,

Daniel Kr�gler


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
ISO
2/2/2011 4:12:20 PM
On 02/02/2011 13:39, chb wrote:
> 
> Hi.
> 
> Is the following code c++:
> 
>    typedef struct {
>        int a;
>        int const b;
>    } C;
> 
> The Intel compiler gives the following warning message:
> warning #411: class "C" defines no constructor to initialize the
> following:
> 
>              const member "C::b"
> 
> But it is possible to initialize b with the old C-style:
> 
> C c = { 1, 2 };
> 
> 
Which is why it is a warning and not an error.


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Francis
2/2/2011 4:13:24 PM
Reply: