Solved

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

Posted on 2015-01-07
2
799 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maze travler 6 62
Better understanding on C++ Class serialization and formats 9 78
Why isn't object file created? 6 68
FMX TEdit KeyUp handler detecting  "enter" key 4 13
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
I'd like to talk about something that is near and dear to my heart: build systems. Without them, building software is all about compiling locally, with software versions everywhere. It can be a mess. Today we are going to discuss building a small di…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

856 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