[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2015-01-07
2
Medium Priority
?
1,013 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

656 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