How to Initialize Two Dimensional Array in the Initializer List of a Constructor

Simple question, what's the proper way to initialize a two dimensional array in an initializer list. I realize this is probably very dependent on platform/compiler and that there probably isn't a universal answer to this question. I am using Windows (XP/Vista/7/8 Visual Studio 2008), Mac (10.6+ LLVM/GCC4.2) and Linux (Ubuntu, Fedora, OpenSUSE GCC)

code
1
2
3
4
5
class foo
{
private:
	char m_byBuffers[64][128];
};


This is what I've got right now
1
2
3
4
foo::foo( ) :
	m_byBuffers( )
{
}


The compiler warning Visual Studio 2008 throws me is this
.\MBSHIDBufferedIOImpl.cpp(26) : warning C4351: new behavior: elements of array 'MBSHIDBufferedIOImpl::m_byBuffers' will be default initialized


So what I'm wondering is...
#1 Is there a better way to initialize my buffer in the initializer list?
#2 Does "will be default initialized" essentially mean it going to be memset to 0? That's what I get out of the documentation. http://msdn.microsoft.com/en-us/library/1ywe7hcy(v=vs.80).aspx What's the deal with that warning?
Last edited on
This is just Visual Studio reminding its users that they finally implemented C++03 (not C++11) initialization rules.

It is not actually called "default initialization", it's called "value initialization", but yes, the chars will be set to zero.
@Cubbi okay so it's just Visual Studio being a noob, there's no better way to do what I'm trying to do?
To zero out a member array of char? m_byBuffers() is the classic way, m_byBuffers{} is the new way, both do the same thing, both seem as good as it gets to me (using clearly-defined core language functionality with almost no code)

I would rather question the need to have a fixed-size 2D character array as a member in the first place.
@Cubbi

First of all, thanks for the responses! You are more useful than google, good on you. 10/10

Well, for your curiosity, it's a buffered IO class that reads in fixed size reports from some HID file. The number of buffers is the first dimension and the size of the reports is the second dimension. It's fixed because the number of buffers and size of reports are just #defines currently.

To your point, I absolutely plan on making a more generic buffered IO that will buffer any IO, not just HID IO.

Let me know if this response is confusing/doesn't make sense and I can try to be more clear.

In short, I agree with you it seems strange to have the fixed size 2D array when I could just take in the # of buffers and size of chunks to read and dynamically create the array based on that. I intend on implementing that in the future, I just had to get this done and tested quickly that's all.
Topic archived. No new replies allowed.