Just to eliminate any confusion, run the following code:
Code:
#include <iostream>
using namespace std;
class A
{
int m_n;
public:
A(int n) : m_n(n)
{
cout << "constructor A" << endl;
}//constructor
A(const A &a)
{
cout << "copyconstruct A" << endl;
m_n = a.m_n;
}//copy constructor
};//A
int main()
{
A a1(4);
A array[] = {A(3), a1};
return 0;
}//main
/*
Output:
constructor A
constructor A
copyconstruct A
*/
The first call to the constructor is for a1.
The second call to the constructor is for array[0].
The copy constructor call is for array[1] and a1 is the parameter.
You don't have to allocate off the heap if the array size if fixed. Consider the following code.
Code:
int main()
{
int n[] = {0, 1, 2, 3, 4};
A array[] = {A(n[0]), A(n[1]), A(n[2]), A(n[3]), A(n[4])};
return 0;
}//main
Whe in doubt, write some test code.
gg