0

I have an array of pointers which is defined: Users **u, now I want to add one more object(pointer, because the class Users is abstract) in this array with this line: this+= new Admin(); Also I have overloaded operator += but still doesn't work. Does anyone know how can I do it without using 'this'??

5
  • You should include code of your operator overload attempt.
    – Bregalad
    May 15, 2015 at 13:27
  • Why don't you use std::vector<Users*> when you need an array of dynamic size?
    – hynner
    May 15, 2015 at 13:27
  • We need more information to answer this. What do you mean by "it doesn't work". Are you getting an error, if so what? Please post your code on how you override the += operator and what makes up Users & Admin
    – JNYRanger
    May 15, 2015 at 13:27
  • DataBase &operator+=(User user){ if(User::nbUsers==1){ this->users=new User*[1]; users[0]=user; } else{ User*temp=new User *[User:nbUsers]; for(int i=0; i<User::nmUsers-1; i++){ temp[i]=users[i]; } delete [] users; temp[User::nbUsers-1]=user; users=temp; temp=NULL; } return *this; } @JNYRanger May 15, 2015 at 13:31
  • @LaStéphanie Please edit your question to include that. It's very difficult to read code in comments.
    – JNYRanger
    May 15, 2015 at 13:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.