New Operator on a Class type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • EmmanuelBarroga
    New Member
    • Aug 2008
    • 1

    New Operator on a Class type

    Is it legal to specify a class type with the new operator like so:

    Code:
    int size = 10;
    
    int *cList = new myClass[size];
  • boxfish
    Recognized Expert Contributor
    • Mar 2008
    • 469

    #2
    Hi,
    I'm not exactly sure what your question is. That code doesn't compile because you are assigning a value of type myClass* to a variable of type int*. It's perfectly legal to make a dynamic array of myClass objects like this:
    Code:
    int size = 10;
     
    myClass *cList = new myClass[size];

    Comment

    Working...