I created a vector like that" typedef std::vector<Client*> Clients" and declared a vector "Clients clients". I specialized the Client class to SpecialClient, so I have:
Expand|Select|Wrap|Line Numbers
- class Client
- {
- public:
- /// Constructor
- Client (void);
- /// Destructor
- virtual ~Client (void);
- /// Register the client
- virtual void show_info (char* name) ;
- /// Get the name.
- void set_name (const char * name);
- private:
- std:string name;
- }
- class SpecialClient
- {
- public:
- /// Constructor
- SpecialClient (void);
- /// Destructor
- virtual ~SpecialClient (void);
- /// Register the client
- virtual void show_info (char* name) ;
- /// Get the details.
- void set_details (const* char details);
- private:
- std:string details;
- }
Expand|Select|Wrap|Line Numbers
- typedef std::vector<Client*> Clients;
- Clients clients;
My function populates the "clients" vector and return it to a calling program. So I have:
Expand|Select|Wrap|Line Numbers
- SpecialClient* cl = new SpecialClient();
- cl->set_name("Client1");
- cl->set_details("Details client 1");
- clients.push_back(cl);
Expand|Select|Wrap|Line Numbers
- Clients obtain_clients () {
- return (clients);
- }
Expand|Select|Wrap|Line Numbers
- Clients cls = obtain_clients();
- int index;
- for(index=0; index < cls.size(); index++) {
- Client* cl = (cls.at(index));
- std::string name = cl->get_name();
- std::cout << "Name: " << name << std::endl;
- SpecialClient * scl = dynamic_cast<SpecialClient*>(cl);
- std::string details = scl->get_details();
- std::cout << "Details: " << details << std::endl;
- }
Thank you.
Nei