On 2007-08-28 18:54, kkirtac wrote:
> Hi, i have a class "myClass", and i want to return two instances of
> the same class from a function. I define an array as follows :
> "myClass sample[2] ;" and i initialize two instances: "myClass
> sample1, sample2 ;"
> "sample[0] = sample1 ; sample[1] = sample2 ; return sample ;" This
> caused the error :
> error C2512 : 'myClass' : no appropriate default constructor available
When you declare the array
myClass sample[2];
both elements of that array will have to be initialised, which means
calling the default constructor. Your class does not have a default
constructor hence the error. You can initialise the array with the
correct values from the beginning like this:
myClass sample[2] = { sample1, sample2 };
> any idea how to return 2 instances and what is wrong with this
> implementation..
To find out how to return two values from a function read the archives,
the question has been answered two times in less than a week.
--
Erik Wikström