Monday, 15 April 2013

Polymorphism and array of pointers problem in C++ -


I am working on a project and it is in a phase that I do not know what is wrong. Here is the simplified version:

Code:

  class base {// This base square is a pure essence public: virtual ~ (base); // Virtual BaseFunk () = 0 required to trigger Destructors in expected classes; }; Class DeriveA: Public Base {Public: DerivedA (SomeClassUseBase * tmp) {tmp - & gt; Register (this); } ~ DerivedA (); Void baseFunc () {// something here is only for DeriveA}}}; Category DerivedB: Public Base {Public: DerivedB (SomeClassUseBase * tmp) {tmp - & gt; Register (this); } ~ Davey B (); Void baseFunc () {// something is here only for DerivedB}}}; Class SomeClassUseBase {Private: Base ** basePrt; Unsigned index index; Public: someClassUseBase (integer number) {basePrt = new base * [number]; // Create an array of points on the objects index = 0; } Zero Register (Base * Base) {// I tried * (BasePR [index]) = * base, but found the basis of the same problem [page] [base] index = index + 1; } Zero checklist () {for (int i = 0; i  

Edit:

The code was not found for the first time, sorry ...

You are making 5 objects (derivaid A / B) in Array Base * B [5], but you do not have access to them in your checklist. Either try to get this array in TMP somehow or try to make the A / B objects generated within the TMP immediately.

At present, two angles are not connected within TMP and inside the main (), and for this reason, in TMP

updates

Also check that the type of unsigned integer matches the type of your loop variable i (currently integer) in the index . The next attempt is to make their methods explicitly in DeriveA / B, virtual (also discard!). Depending on the compiler, this may be an issue that resolves your call to basefunction () still the 'empty' body of the base. Finally, if it is actually C ++, then you can try to work with references, so your constructor looks like this

  DeriveA (SomeClassUseBase & amp; tmp) {Tmp.register (this); }  

Note the use of dot-operator instead of '->', it makes things easier to read and maintain.


No comments:

Post a Comment