Dynamically allocating an array of objects

前端 未结 7 1597
挽巷
挽巷 2020-11-22 13:05

I have a class that contains a dynamically allocated array, say

class A
{
    int* myArray;
    A()
    {
        myArray = 0;
    }
    A(int size)
    {
           


        
7条回答
  •  盖世英雄少女心
    2020-11-22 13:26

    1. Use array or common container for objects only if they have default and copy constructors.

    2. Store pointers otherwise (or smart pointers, but may meet some issues in this case).

    PS: Always define own default and copy constructors otherwise auto-generated will be used

提交回复
热议问题