C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

non-static const struct memeber initialization

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Yong
Guest





PostPosted: Wed Apr 28, 2004 9:25 am    Post subject: non-static const struct memeber initialization Reply with quote



Does the latest C++ standard support the following codes without any
warning:

struct unknown {
const int i;
const char str[4];
}

This will gave me a compilation error several years ago. If this is
supported now, what's the right way of initialization?

Thanks in advance.

Yong

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Francis Glassborow
Guest





PostPosted: Wed Apr 28, 2004 7:22 pm    Post subject: Re: non-static const struct memeber initialization Reply with quote



In message <fce5c344.0404270917.122bd189 (AT) posting (DOT) google.com>, Yong
<yongyin2000 (AT) hotmail (DOT) com> writes
Quote:
Does the latest C++ standard support the following codes without any
warning:

struct unknown {
const int i;
const char str[4];
}

This will gave me a compilation error several years ago.

Well the only error is the omission of the terminating semicolon so I
cannot imagine why you ever had a problem.

Quote:
If this is
supported now, what's the right way of initialization?

#include <iostream>
#include <string>

struct unknown {
const int i;
const char str[4];
};


int main(){
unknown uk = {3, "abc"};
std::cout << uk.i << ' ' << uk.str <<'n';
}

However you can only currently use the assignment style initialisation
syntax for brace initialisers. That is one of the things I want to
change in a future C++ Standard.


--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


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

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.