Solved

C++ cannot specify explicit initializer for arrays  [VS Community 2013 Update 4]

Posted on 2015-01-07
2
835 Views
Last Modified: 2015-01-08
Hello, How are you?

I have this error:

Error      1      error C2536: 'Address::Address::Enemys' : cannot specify explicit initializer for arrays

class Address{
public:
	static Address& Instance(){
		static Address addr;
		return addr;
	}
	const DWORD Enemys[64] = { 0 };
}

Open in new window


I was searching in Google, and it says this is a bug.


I'm using Visual Studio Community 2013 Update 4.

What i do? I need to use singleton.

Ty!
0
Comment
Question by:Júlio
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 40537080
It is a bug, that should not happen.

>> What i do? I need to use singleton.

One simple workaround would be to

class Address{
public:
	static Address& Instance(){
		static Address addr;

                if (!initialized) {

                   memset(Enemys,0,sizeof(Enemys));
                   initialized = true;
                }

		return addr;
	}
	const DWORD Enemys[64] = { 0 };
        static bool initialized;;
}
                                  
bool Address::initialized = false;

Open in new window

0
 

Author Comment

by:Júlio
ID: 40537616
hum,

Now other error:

Error      3      error C2070: 'unknown': illegal sizeof operand
7      IntelliSense: a nonstatic member reference must be relative to a specific object
Error      2      error C2597: illegal reference to non-static member 'Address::Enemys'      

i think will use a vector. This is given to many errors. Ty for your time jkr!

EDIT: yes, i just changed to vectors and it's working fine now
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question