I need to store the references to classes derived from C ++. I use welded space for the shared class (It needs to have different types of derivative classes), however, it is important that the container has original pointers, which is not in the case of vectors (or other stell containers), if I am wrong I'm not. Is there a way to do this in the original C ++, or do I have to use special containers like Boost's PCR_Vector?
Edit: This is my test code:
class Foo {public: fu () {} virtual ~ fu () {} Virtual Zero set_x (int i) = 0; }; Square bar: Public fu {public: times () {} zero set_x (int i) {it-> X = i; } Int x; }; Int main () {again and again; // ptr std :: cout & lt; & Lt; & Amp; Bar & lt; & Lt; "\ N"; Std :: vector & lt; Foo * & gt; Less important things; Foos.push_back (& amp; bar); // various PTR values std :: cout & lt; & Lt; & Amp; FOS [0] & lt; & Lt; "\ N"; Less important things [0] - & gt; Set_x (1); // However, change std :: cout & lt; & Lt; Bar.x; Return 0; }
Thank you in advance,
Jenna
In your example above, the printer you are printing does not have the value of the indicator's address.
Instead of:
// various ptr values include std :: cout & lt; & Lt; & Amp; FOS [0] & lt; & Lt; "\ N";
Do
// various ptr values std :: cout & lt; & Lt; Fees [0] & lt; & Lt; "\ N";
In addition to your vector & lt; Foo * & gt;
will work fine.
Comments
Post a Comment