Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
How to initialise aggregate member?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="John Carson, post: 2573046"] I might ask why, but...you could do this: MyClass() { obj.i = 5; obj.d = 45.67; } Alternative, if you want to use an initialisation list, you could do this: struct MyStruct { int i; double d; }; class MyClass { private: MyStruct obj; static MyStruct ms; public: MyClass() : obj(ms) { } }; MyStruct MyClass::ms = {5, 45.67}; int main() { MyClass obj; return 0; } i.e., you manually initialise a static instance of the struct and then you can use the static variable to initialise your member variable for every object of the class that you create. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
How to initialise aggregate member?
Top