Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,025 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,542 people online right now. Registration is fast and FREE... Join Now!




question (polymorphism?)

 
Reply to this topicStart new topic

question (polymorphism?), little confused

okyup
29 Nov, 2006 - 05:00 PM
Post #1

D.I.C Head
Group Icon

Joined: 6 Nov, 2006
Posts: 207


Dream Kudos: 175
My Contributions
Well i have a little problem thats difficult for me to explain.

I want to do something like this. Basically i want to be able to pass multiple vectors of derived objects into a function that will process them all with the same functions from the abstract base.

CODE

vector<derived1> der1;
vector<derived2> der2;
...
next('A',der1);
next('B',der2);
...
void next(char c,vector</*SOMETHING?*/> &VAR)
{
    abstractBase *ptr,*ptr2;
    if (c=='A')
    {
        derived1 newd;
        ptr=&newd;
    }
    if (c=='B')
    {
        derived2 newd;
        ptr=&newd;
    }
    for (i=0;i<VAR.size();i++)
        {
            ptr2=&VAR[i];
            check=ptr2->keep();
            if(!check)
            {
                VAR.erase(i);
                continue;
            }
            check=ptr2->double();
            if(check)
            {
                VAR.push_back(newd);
            }
    ...
...


So im basically wondering if i could put something in place of /*SOMETHING*/ or maybe do this with a template? Thanks for any help. Im basically assuming there is some way to do this otherwise i cant see any use for polymorphism, assuming thats what you call this.
User is offlineProfile CardPM
+Quote Post

cipherence
RE: Question (polymorphism?)
29 Nov, 2006 - 05:16 PM
Post #2

D.I.C Regular
Group Icon

Joined: 1 Apr, 2006
Posts: 260



Thanked: 1 times
Dream Kudos: 650
My Contributions
for any thing about C++ you could try cplusplusprogramming.com or something like that, they have some kickin tuts.
User is offlineProfile CardPM
+Quote Post

okyup
RE: Question (polymorphism?)
29 Nov, 2006 - 08:31 PM
Post #3

D.I.C Head
Group Icon

Joined: 6 Nov, 2006
Posts: 207


Dream Kudos: 175
My Contributions
Nvm i figured it out using templates.

Still seems to me that there should be another way tho. :-P
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 09:27PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month