intersting problem with inheritance and iterators

P

puzzlecracker

struct A{
std:string name;

};

struct B:public A{



};
std::vector<A*>vec;
....

std::vector<A*> const_iterator beg=vec.begin(), end=vec.end();

for(;beg!=end;beg++)
std::cout<<beg->name<<std::endl;


ok, std:string name from class A is NOT visible. WHY? what is the
solution
 
M

Mark P

puzzlecracker said:
struct A{
std:string name;

};

struct B:public A{



};
std::vector<A*>vec;
...

std::vector<A*> const_iterator beg=vec.begin(), end=vec.end();

for(;beg!=end;beg++)
std::cout<<beg->name<<std::endl;


ok, std:string name from class A is NOT visible. WHY? what is the
solution

Apart from the other syntactic errors, beg->name means (*beg).name
however (*beg) is of type A* const. Probably you want (*beg)->name.

Mark
 
P

puzzlecracker

Mark said:
Apart from the other syntactic errors, beg->name means (*beg).name
however (*beg) is of type A* const. Probably you want (*beg)->name.

Mark\

here is the exact code - what is wrong:


struct A{
std::string name;
};

struct B{
std::vector<A*> dirent;
};
....

void FileSystem::dump(A * e){

if(e==0) return;

vector<A*>::const_iterator
beg=(e->dirent).begin(),end=(e-dirent).end();
 
M

Mark P

puzzlecracker said:
here is the exact code - what is wrong:


struct A{
std::string name;
};

struct B{
std::vector<A*> dirent;
};
...

void FileSystem::dump(A * e){

if(e==0) return;

vector<A*>::const_iterator
beg=(e->dirent).begin(),end=(e-dirent).end();

That's the exact code? Why do you have "..." in the middle of your
code? Why do you have an unmatched brace '{'? Why is there no
definition of the class FileSystem? What does "e-dirent" mean? And so on.

Don't expect much help until you put in a little more effort towards a
clear and comprehensible question.

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top