473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Initializing Non-default-constructible Elements in a Member Array

Hello all,

In this code:

class Bar {
public:
Bar(int) {} // ***Not default constructible***
};

class Foo {
public:
Foo() : m_Bar({Bar(1), Bar(2)}) {} // Not syntactically correct!
private:
Bar m_Bar[2];
};

What is the proper way to initialize m_Bar? Thanks to all!

Best,
Dave

Nov 6 '07 #1
1 1616
be***********@yahoo.com wrote:
In this code:

class Bar {
public:
Bar(int) {} // ***Not default constructible***
};

class Foo {
public:
Foo() : m_Bar({Bar(1), Bar(2)}) {} // Not syntactically correct!
private:
Bar m_Bar[2];
};

What is the proper way to initialize m_Bar? Thanks to all!
There is no way, proper or otherwise. Use a a standard container
(vector) which can be copy-initialised from a static Bar array.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: hrmadhu | last post by:
Hi, I wish to declare a vector of deque of int, which I do as follows. #include<vector> #include<deque> #include<iostream> using namespace std; int main(int argc, char* argv) {
4
by: trying_to_learn | last post by:
I'm learning consts in C++ and the book says that u have to initialize non-static consts inside the constructor initializer list, however "const string* stack" isn't initialized in the constructor...
2
by: Andrew Ward | last post by:
The following program compiles and runs fine on my compiler (vc7.1): #include <memory> using namespace std; class X {}; auto_ptr<X> foo() {
7
by: vikky | last post by:
hi all, Out of sheer curosity, I decided to initialize an integer with a number bigger than INT_MAX, however I still am not able to justify its output. Here is the program : #include<stdio.h> ...
4
by: Varun Kacholia | last post by:
Hi everyone, I have the following piece of code: vector<MyClass*> my_vector(10, NULL); However this throws the following errors: myfile.cc: warning: converting NULL to non-pointer type...
9
by: Christian Christmann | last post by:
Hi, I have problems to initialize a static struct. Here is the meaningful part of the code: int main() { int pA = -100; struct globalMixed4 {
13
by: John | last post by:
Is this a valid C++ program that will not crash on any machine? #include <iostream> using namespace std; int main( void ) { int i; cin >i; double X; X = 1123;
38
by: junky_fellow | last post by:
Guys, I was just looking at some code where to initialize an integer with all F's following statement is used; unsigned int i = -1; I want to know if this is the right way of doing the...
13
by: WaterWalk | last post by:
Hello. When I consult the ISO C++ standard, I notice that in paragraph 3.6.2.1, the standard states: "Objects with static storage duration shall be zero-initialized before any other...
2
by: Frostmur | last post by:
Hi !! I'm trying to convert C code to C++. This is my function: static void (*selection)(void) = NULL; static void (*pick)(GLint name) = NULL; void zprSelectionFunc(void (*f)(void))
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.