 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Yong Guest
|
Posted: Wed Apr 28, 2004 9:25 am Post subject: non-static const struct memeber initialization |
|
|
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
|
Posted: Wed Apr 28, 2004 7:22 pm Post subject: Re: non-static const struct memeber initialization |
|
|
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 |
|
 |
|
|
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
|
|