|
-
July 13th, 2008, 06:19 PM
#1
Problem passing arrays to constructors
I have a class whereby one if its members is an array of objects from another class (not derived). When I construct this class, I want to pass an array of these objects to it, whereby each object of this class instantly has an array of the [other] objects which it can later access. How do I go about writing the constructors? Here is what I have tried:
Class ThisClass
{
private:
enum { MAX = 10 };
OtherClass m_array[MAX];
int m_one;
int m_two;
public:
ThisClass() : int m_one(0), int m_two(0) , m_array (WHAT GOES HERE) {}
ThisClass(int one, int two, int array[]) : m_one(one), m_two(two), m_array(array) {}
This does not compile. I am confused when I should include the square brackets after the array name. When I experiment with and without them I get different errors.
To clarify: When I create an object of the above class I would like to pass it an array of objects of another class. I am yet to find a solution on the net.
A common compile error I am getting is "cannot specify explicit initializer for arrays"
Hope you can help. Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|