'Using regular pointers on Polymorphism c++

I'm trying to learn Polymorphism in C++, and the way I've been learning it was with raw pointers or smart pointers but then I've been trying to use regular pointers this time and I even tried to add the pointers to a vector from the constructor like this:

std::vector<bank_account*> bank_accounts; 

bank_account::bank_account(std::string Name, int Balance)
    : name{Name}, password{create_random_passowrd()}, balance{Balance}, Id{create_ID()} {}

saving_account::saving_account(std::string Name, int Balance, float Interest)
    : bank_account{Name, Balance}, interest_rate{Interest}{
        bank_account *ptr = this;
        bank_accounts.push_back(ptr);
    }

I did things this way because I would like to avoid doing "push.back" to add every object I create when calling the constructor(every attempt I did with smart pointers or raw pointers I always ended up calling the same constructor again and then creating an infinite loop) and also to achieve polymorphism without worrying about memory leaks in this situation, but I'm finding myself with some issues on using virtual functions and I think it might have something to do with this. I'd be really glad if you guys could tell if this is a good idea or not and also I'd like to say thanks for your attention!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source