Solved

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

Posted on 2015-01-07
2
656 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now