Iteration inherited list

I have two classes inherited from the third class and they are stored in a list.

I am trying to iterate the list and call each The implementation function of a class, but the code cannot be compiled.

This is my code:

class A
{
public:

virtual void foo ()=0;
};

class B :public class A
{
public:< br />
void foo();
}

class C :public class A
{
public:

void foo();
}

std::list listOfClasses;

listOfClasses.push_back (new B());
listOfClasses.push_back (new C());

for(std::list::iterator listIter = listOfClasses.begin(); listIter != listOfClasses.end(); listIter++)
{
listIter->foo()
}

This code cannot be compiled, I receive the following error message (for the line listIter->foo()):< /p>

‘foo’: Not a member of’std::_List_iterator< _Mylist>‘

Any thoughts?

Your container contains pointers, so you need to dereference them:

(*listIter)->foo();

I have two classes inherited from the third class, they store In a list.

I am trying to iterate the list and call the implementation function of each class, but the code cannot be compiled.

This is my code:< /p>

class A
{
public:

virtual void foo ()=0;
};

class B :public class A
{
public:

void foo();
}

class C :public class A
{
public:

void foo();
}

std::list listOfClasses;

listOfClasses.push_back (new B());
listOfClasses.push_back (new C());

for(std::list::iterator listIter = listOfClasses.begin(); listIter != listOfClasses.end(); listIter++)
{
listIter->foo()
}

This code cannot be compiled, and I receive the following error message (for the line listIter->foo()):

‘foo’: not a member of’std::_List_iterator< _Mylist>‘

Any thoughts?

Your container contains pointers, so you need to dereference them:

(* listIter)->foo();

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2843 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.