473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

intersting problem with inheritance and iterators


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

Sep 27 '05 #1
3 1108
puzzlecracker wrote:
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
Sep 27 '05 #2

Mark P wrote:
puzzlecracker wrote:
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\


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();

Sep 27 '05 #3
puzzlecracker wrote:
Mark P wrote:
puzzlecracker wrote:
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\

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
Sep 27 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: John Perks and Sarah Mount | last post by:
Trying to create the "lopsided diamond" inheritance below: >>> class B(object):pass >>> class D1(B):pass >>> class D2(D1):pass >>> class D(D1, D2):pass Traceback (most recent call last): File...
6
by: Fraser Ross | last post by:
Algorithms cannot be used with input stream iterators? Is copying the range to a temporary container before using the algorithm the usual thing to do? Fraser.
18
by: deancoo | last post by:
I have gotten into the habit of often using copy along with an insert iterator. There are scenarios where I process quite a lot of data this way. Can someone give me a general feel as to how much...
8
by: babak | last post by:
Hi everyone I have a problem with Iterators and containers in STL that hopefully someone can help me with. This is what I try to do: I have an associative (map) container and I have a...
4
by: kalita | last post by:
Hi All, typedef std::list<int> Cont; void f(Cont &c1, Cont &c2) { Cont::iterator it = c1.begin(); c1.swap(c2); it == c2.begin(); // is this ill formed? }
13
by: Dan Tsafrir | last post by:
is the following code standard? (cleanly compiles under g++-4.0.2): struct Asc { bool operator()(int a, int b) {return a < b;} }; struct Des { bool operator()(int a, int b) {return b > a;} };...
1
by: Yves | last post by:
Hi! I was fiddling around a bit with iterators and I came across some strange behaviour. I have the following simple code: -- class A(object): def __init__(self, n): self.n = n
3
by: Bangalore | last post by:
Hi, In the following program, eventhogh two member function declared under private section of the derived class are accessable by derived class pointer. Please clarify me how can derived class...
6
by: gexarchakos | last post by:
Hi there, Please give me at least a hint... I have a problem implementing a function object with parameters two iterators. That is: A class 'node' produces messages using a routing policy....
18
by: desktop | last post by:
1) I have this code: std::list<intmylist; mylist.push_back(1); mylist.push_back(2); mylist.push_back(3); mylist.push_back(4);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.