473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

initialization of a static member array of objects

class A
{
private:
explicit A( int i ) {}
A( const A& );

public:
static const A arr[2];
};

const A A::arr[] = { A(0), A(1) };

int main ()
{}

Consider the above code and note that the copy ctor for A has been
declared but not defined. gcc reports a link error to the copy ctor
which I assume means that it's trying to initialize "arr" by copying the
temporaries A(0) and A(1). Is there another way to initialize this
array without defining the copy ctor?

-Mark
Aug 11 '06 #1
2 5025
Mark P wrote:
class A
{
private:
explicit A( int i ) {}
A( const A& );

public:
static const A arr[2];
};

const A A::arr[] = { A(0), A(1) };

int main ()
{}

Consider the above code and note that the copy ctor for A has been
declared but not defined. gcc reports a link error to the copy ctor
which I assume means that it's trying to initialize "arr" by copying
the temporaries A(0) and A(1). Is there another way to initialize
this array without defining the copy ctor?
No.

If you specify '0' and '1' without wrapping them in 'A()', your
compiler should complain because your A(int) is declared "explicit".
If you do wrap them, like you did, each array element is copy-
initialised, and that requires a copy c-tor. Provide one.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 11 '06 #2
Mark P posted:
Is there another way to initialize this
array without defining the copy ctor?

Short answer: No.

Long answer: Yes, but it's verbose.

This is a defect in the C++ programming language. This may interest you:
http://groups.google.ie/group/comp.s...40c08d2?hl=en&

--

Frederick Gotham
Aug 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: cppaddict | last post by:
I have class with two static member objects, one of type int and one of type vector<int>. static int myStaticMemberInt static vector<int> myStaticMemberVector; I know how to initialize the...
2
by: Neno | last post by:
Hi, I have a linkage error that has something to do with the use of a static member array and I can't understand how to solve the problem. Can someone help me please? In detail: A class Month...
4
by: Agoston Bejo | last post by:
Hello there, is it possible to initialize such a static member that need some algorithm for initializing? What I mean is: ---------------------------------- Example: Platform VC++7.1...
3
by: Tran Tuan Anh | last post by:
Dear all, I am new with C++ and very confused with some features. Really appreciate if you can explain to me some of stuffs below. I define a class: class A { static A* instance = 0; };
16
by: Steven T. Hatton | last post by:
As far as I know, there is no way to provide a default value for the argument to the constructor A::A(char (&array)) in this example. Correct? struct A{ A(char (&array) ){...
5
by: partha.p.das | last post by:
Here is my class: class MyClass { public: MyClass(); ~MyClass(); private:
3
by: johnmmcparland | last post by:
Hi all, I would like to have a static constant array inside a class definition which would contain the number of days in each month (I am writing a Date class as an exercise). However my...
10
by: shanknbake | last post by:
I'm getting the following compile-time error: error C2352: 'Person::getCount' : illegal call of non-static member function Here is my getCount function declaration:...
7
by: Jim | last post by:
Hi, I'm trying to build a simple data table for all my classes to use. I don't want to use a vector. The data is stored in class freqoffset class freqoffset { public:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.