c++ - Create multiple objects in class -


i have class use make linked lists. in main want create more 1 lists. mean without overwriting previous one. how can without having give new name create object of class. if example had 1000 lists couldn't give 1000 different names them. tried using array of objects don't seem work.

edit:sorry inconvenience i'm not allowed use vector. here's code:

 list **root; root=new list*[m]; (int i=0;i<m;i++) {     root[i]=null;     root[i]=new list();  } 

this in main use

 (*root[pos]).addnode(b,a); 

no matter pos use go same list.

if created linked list class linkedlist create std::vector of lists. can iterate on them , whatever you'd like.

#include <vector> int main() {     std::vector<linkedlist> lists(1000);     (auto& list : lists)     {         // each list     } } 

if know how many linkedlist objects want make, , value fixed, use std::array

#include <array> int main() {     std::array<linkedlist, 1000> lists;     (auto& list : lists)     {         // each list     } } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -