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 10705 articles. 11 followers. allnor (8507) is leader. Post Follow

2 Replies
1290 Views

Similar Articles

[PageSpeed] 4
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:
Similar Artilces:

Sas to excel: text variable values beginning with '=' etc
SAS-Lers: I have a dataset that I'm trying to write out to Excel using ODS HTML but am having trouble with Excel converting some of my variable values during the output operation. For example, my code looks roughly like this: ods html style=3Dbarrettsblue file=3D"&output_folder\&curr_year.POYHU_Final.xls" ; proc print data=3Dforxls ; var Var1 Var2 Var3 ; run ; ods html close ; And the variable Var1 has some values that Excel thinks are either exponential numbers or cell references and when I open the final report in Excel things are messed up. In other ...

Overriding const member function with non-const
Hi all, I've got a question regarding overriding const member functions with non-const functions. Let's say I've got a base class defined as follows: /*******************/ class Foo { public: Foo(); virtual ~Foo(); virtual void Run() const; virtual void DoSomething(); } /*******************/ Now, what I want to do is create another class derived from it, and override the Run() method. However, I will need to call DoSomething() from this new version of Run(), even though Run() is const and DoSomething() is not. I'm not concerned about whether I should be ...

When copy object of class type, all members shouldn't be non-public?
--------- quotation --------- The default method of initialization using special member functions is to perform a bit-for-bit copy from the initializer into the object to be initialized. This technique is applicable only to: 1. Objects of built-in types. 2. Pointers. 3. References. 4. Objects of class type, where the class has no private or protected members, no virtual functions, and no base classes. --------- of of quotation --------- I saw these description when read some documents. Does the fourth item says that when perform initialization using copy ctor or assignment using operator =...

Question on using different types within a struct.
I am looking to use structs in my program so that I can pass them as "packets" over a network socket created within the program. I am particularly interested in the following scenario: typedef struct A { int a; int b; int c; }pkt_A; typedef struct B { int def; char msg[32]; }pkt_B; typedef struct C { double d; char msg1[32]; char msg2[32]; }pkt_C; typedef struct D { int code; void *body; }pkt_D; Now I want struct D to act as the container for the other structs that are created. I am wondering if this would work or if there is a better way to d...

destroying IO::Handle without close()ing the file
The comment in IO/Handle.pm says: # There is no need for DESTROY to do anything, because when the # last reference to an IO object is gone, Perl automatically # closes its associated files (if any). However, to avoid any # attempts to autoload DESTROY, we here define it to do nothing. So how do people destroy the handle without close()ing? I think some POSIX magic should be done, but which one? Puzzled, Ilya P.S. WHY? Suppose I make a same-fd duplicate (open "<&=11"). Now I want to get rid of it - but I must not close() the orig...

subclass has a variable that is subclass of same superclass
I have been running this scenario in my head for a while. In the surface it seems fine, but I keep thinking that somehow it will cause problems. class A { } class B extends A { } class C extends A { B myB; } Class B is a A Class C is also a A but also has a B which is in turn a A. Is there anything wrong with having a variable in a class of a type that inherits from the same parent that the class itself inherits from? Thanks. "jstorta" <john@storta.net> wrote in message news:1140381778.634371.301640@g43g2000cwa.googlegroups.com... >I have been running this...

Surprising struct initialization
I suppose you can never know C++ fully. I would have never guessed this actually compiles and works: struct Point { int x, y; }; struct Line { Point endpoint[2]; int weight; }; Line createLine(int sx, int sy, int ex, int ey) { Line l = { sx, sy, ex, ey, 1 }; return l; } Both gcc and Visual Studio 2005 compile that happily. My question would be: Is that *really* correct, or are both compilers simply being lenient? What are the exact rules for the initialization blocks of structs? Juha Nieminen wrote: > I suppose you can never know C++ fully. I would have never ...

To coerce or not...? struct sockaddr vs struct sockaddr_in
Having updated my Debian system it now complains that I am using an incompatible pointer type in warnings such as "passing arg 2 of 'bind' from incompatible pointer type" from code, struct sockaddr_in sockad1; .... retval = bind (sock1, &sockad1, sockad1len); I can coerce the pointer with retval = bind (sock1, (struct sockaddr *) &sockad1, sockad1len); but that seems to me to be bad style - doesn't it overrides the compiler's checking? I cannot instead change the defintion to struct sockaddr sockad1 because my code uses members of the sockaddr_in structure...

Re: Substiuting variables within an integral
Hi, Ed, there is a package "Presentations" written by David Park that contains such operators and examples of how to do transformations of that sort. You may also do it without the package (though less beautiful), if your aim is simply to insert a new variable and see what is your integral looking like before its actual evaluation. As an example try the one below. Assume you are looking for the integral J=Integrate[func[y], y], where func[y] is a function in question: rule = {y -> q[x], \[DifferentialD]y -> D[q[x], x]*\[DifferentialD]x}; (* This is your tra...

fix variable
hello, unfortunately i&#180;m pretty unexperienced in workin with matlab, but i&#180;m trying to get better. therefor i need some help however. in my special problem i want to program a loop, in which fixed variables (large number)should be used. the variables are saved in an ..txt file for different points of time. depending on the regardet point of time certain variables (for example t=0) should be used in the loop. how can i copy the values in my m.file? must they be written in this file themselves (for every point of time) or can they be copied in by matlab out of the .txt fil...

Re: How to count unique members based on number of claims on #3
Yes, I did miss the group by- thanks for catching that! -Mary ----- Original Message -----=20 From: Anindya Mozumdar=20 To: SAS-L@LISTSERV.UGA.EDU=20 Sent: Wednesday, March 04, 2009 11:29 PM Subject: Re: How to count unique members based on number of claims on = different dates? > First aggregate the data by date: > > proc sql; > create table aggregate1 as > select distinct id, srv_dt > from claims; > quit; > > Then count the number of claims: > > proc sql; > create table claims_counts_on_different_dates > as select ...

struct
I can represent struct like the following using { a, b } it's similar to list in PERL right? in perl I can do something like - ( a, b, c ) ########################## typedef struct { Setup setupID; const char *setupString; } SetupCode; static const SetupCode g_SetupRecordTable[] = { {GRAPHIC_TEST, "graphic"}, {KEYBOARD_TEST, "keyboard"}, {MY_TEST, "mytest"} }; Carmen Sei wrote: > I can represent struct like the following using > > { a, b } The above cannot be used to represent a struct, only to intialize it (see below). > it...

member pointer to struct data
Hi all, I didn't find this explicitly stated in the FAQ so I wanted to verify it. A class and a struct are the same except for their default access levels, right? So then, if I wanted a member pointer in my class to point to an int in a struct I would have to declare the member pointer to be: class MyClass { MyStruct::int* piMyIntPntr; }; Is that correct? -- Best wishes, Allen Allen wrote: > Hi all, > > I didn't find this explicitly stated in the FAQ so I wanted to verify > it. > > A class and a struct are the same except for th...

Re: Get the name of program as macro variable #2
Hi Mike, It already is an available environment variable. SYSPROCESSNAME will have your program name if it was run as a batch program, and will have "DMS process" for the interactive session(Display Manager System). For knowing which programs you have open in your interactive session, you can *play* with sashelp.vextfl and filter out the core pieces. Of course, depending upon sequence of events and other factors plus the randomid, there can be caveats in working out some logic to make this view usable. Hope this is helpful. Mark Terjeson Senior Programmer Analyst, IM&R Rus...

Omitting arguments for default-valued parameters through pointer-to-member call
Hello all, This post is in reference to the topic addressed in Herb's GOTW #64. I have a need to create a pointer-to-member to a member function that has an unknown number of parameters; however, it is certain that the member function is callable with no arguments (due to the presence of default values for all parameters). For the reasons that Herb states, this cannot be done. However, the thought occurred to me that the fact that the member function is callable with no arguments (and this is indeed the way I want to call it) might open up an avenue for me to get the job done with some...

GA variable selection crossover problems
hello. I am using a GA to find good subsets of variables which produce good neural netowork models. I encode my individuals in binary, of course. I previously needed help controlling the mutation function from mutating me to too many variables. Obviously, the more variables you let in your neural network, the better the network may perform. Ideally, i would also be selecting for Q-squared inside the GA, but that would be computationally too expensive. Quality of fit will be done on models after the GA has finished. So i do need to restrict the number of 1's in a given individual. As ...

Coding standard rule for using struct's..?
If you were tasked with creating a guideline which defines what a struct can/cannot contain, or should/shouldn't do, what would it look like? One reason for the guideline might be to prevent struct's from becoming large nested classes, which can happen over time. Some example guidelines might look like the following: Extreme... 1) A struct should not contain any member functions, or objects containing member functions. Restrictive... 2) The only methods a struct should contain are those which support member initialization, assignment & copying of the struct. Open... 3) Use your...

how do I support "delay" in my interpreter without breaking my back?
hi how do I support "delay" in my interpreter without breaking my back? dillogimp@gmail.com writes: > how do I support "delay" in my interpreter without breaking my back? Copy R5RS example implementation. It's in section 6.4 under "force", but the entry for "delay" does point there. On Apr 2, 2:08 pm, Jussi Piitulainen <jpiit...@ling.helsinki.fi> wrote: > dillog...@gmail.com writes: > > how do I support "delay" in my interpreter without breaking my back? > > Copy R5RS example implementation. It's in section...

Passing external variable to a GUI
Hi, I need to pass an external variable (a serial object to be precise) to make it visible "inside a GUI". What I want to do is gathering data from a serial port after pressing a GUI button. The serial object is opened in workspace. I've got GUI generated in Guide. I tried to modify the first (opening function) as: function varargout = gui(s1,varargin) %s1-serial object and send s1 from workspace But when the start_Callback procedure executes after pressing button s1 suddenly changes from seial object to a "Start_Callback" string (???) and the va...

Re: Missing variables #6
On Mon, 6 Oct 2008 20:23:56 -0400, Lou <lpogoda@HOTMAIL.COM> wrote: >Randy wrote: >> Dear All: >> My data is as follows >> >> varID >> 1 >> 2 >> 3 >> 4 >> 0 >> 7 >> 8 >> 0 >> 10 >> 11 >> 12 >> 0 >> 16 >> and so on >> I need to construct another var, VARID_one >> where >> varid varid_one >> 1 1 >> 2 2 >> 3 3 >> 4 4 >> 0 6 >> 7 7 >> 8 8 >> 0 9 >&...

how to convert c struct to java classes
1) how to convert c struct to java classes 2) How do i code the function pointers wriiten in c to java? On Wed, 23 Dec 2009 02:03:25 -0800 (PST), warrior <chandu.kushi@gmail.com> wrote, quoted or indirectly quoted someone who said : >1) how to convert c struct to java classes see http://mindprod.com/project/readc.html http://mindprod.com/project/structreaderamanuensis.html >2) How do i code the function pointers wriiten in c to java? see http://mindprod.com/jgloss/delegate.html http://mindprod.com/jgloss/callback.html -- Roedy Green Canadian Mind Products http:...

Bug in struct.pack?
from struct import pack >>> pack("B", 1) '\x01' >>> pack("BB", 0, 1) '\x00\x01' >>> pack("BI", 0, 1) '\x00\x00\x00\x00\x01\x00\x00\x00' >>> calcsize("BI") 8 >>> calcsize("BB") 2 Why does an unsigned char suddenly become 4 bytes long when you include an unsigned int in the format string? It's consistent behaviour but it's incorrect. Also. >>> calcsize('BL') 8 >>> calcsize('BBL') 8 >>> calcsize('BBBL') 8 ...

Re: wildcard search for string variables
Alex, Below are some alternatives .... The second alternative was recently discussed on SAS-l. http://listserv.uga.edu/cgi-bin/wa?A2=ind0601e&L=sas-l&F=&S=&P=22263 data example; input profession $20.; /* one way ... */ if prxmatch('/^(teach|edu)/i',profession) then recoded=1; else recoded=2; /* other conditions here */ /* another way ... */ if upcase(profession) in: ('TEACH','EDU') then _recoded=1; else _recoded=2; /* other conditions here */ datalines; dentist welder teacher History teacher Educator nurse RN LPN business owner CE...

get members who have birthday this week
Hi All, I want to display all members who have their birthday the coming week. I tried some code but it doesn't return any records. Probably because it looks for the date of birth instead of just the month and day: $today = date("d-m-Y"); $birthday = $row['birthday']; $sql = mysql_query("SELECT * FROM myMembers WHERE birthday BETWEEN $today AND $today+7"); Can anyone help me out here? Marco On 6/29/2011 5:20 PM, Co wrote: > Hi All, > > I want to display all members who have their birthday the coming week. > I tried some code but it doesn't ...

Text and variable in one line
How do you display both a text and a numerical value for a variable in just one line. For example, here are my variable x = 2; How do i display the result as The value of x is 2. I tried disp('The value of x is'); disp(x); but the numerical value is not in line with the text. Thanks fprintf('The value of x is %i.\n',x) "Ben " <benlawr2000@yahoo.com> wrote in message <gq8s3k$n21$1@fred.mathworks.com>... > How do you display both a text and a numerical value for a variable in just one line. For example, here are my variable > > x = 2; >...