hello, i'm trying desperately to recover my c++ knowledge. I haven't done c++ for a year and now i'm facing some problems. Please help.
I.
How to type cast this:
class A { virtual c Read(); }
class B: public A {
public c Read(){
D d ;
return d;
}
}
class C {}
class D: public C {}
void main (){
B b;
D d = b.Read(); // how will i convert it??
}
}
i tried:
D * d = dynamic_cast<D*>(&b.Read());
but it gives "taking address of temporary" (section III)
II.
I write the following:
class A {
public A *succ;
}
void main(){
A a;
for(;a != NULL;a = a.succ); // EDIT: Multiple markers at this line
- no match for ‘operator!=’ in ‘a != 0’
- lvalue required as left operand of assignment
}
/*I don't need to overload the operators! They should work implicit, shouldn't they?*/
III.
/*Class structure is same as from section I*/
class A { virtual c Read(); }
class B: public A {
public c Read(){
D d ;
return d;
}
}
class C {}
class D: public C {}
void main (){
B b;
C *c = &(b.Read()); // error/warning: taking address of temporary? !!edited!! > D * d is changed to C *c
}
}
/*Is this error serious? Will it delete itself? how can i get rid of the error?*/