[ Mirko Rajkovača @ 27.12.2006. 00:27 ] @
imam sledeci problem:
Klasa B je nasledjena iz klase A, prilikom kreiranja klase B prvo se poziva konstruktor klase A, koji bi trebao da pozove jednu virtuelnu funkciju koja je overlodovana(srpski engleski) od strane klase B, medjutim izvrsava se funkcija klase A (sto je normalno za C++ prilikom konstruktora bazne klase koliko sam video na netu) medjutim meni je potrebno da se pozove funkcija klase B. Nadam se da vam je jasno sta hocu da postignem. Svaka ideja je dobrodosla
Hvala unapred!
[ kiklop74 @ 27.12.2006. 01:29 ] @
Procitaj ovo:

http://www.artima.com/cppsource/nevercall.html

Citat:
Don't call virtual functions during construction or destruction, because such calls will never go to a more derived class than that of the currently executing constructor or destructor.


Ukratko menjaj dizajn klase.

[ Goran Arandjelovic @ 27.12.2006. 10:18 ] @
Mislim da je kiklop u pravu.
E, sada ako baš želiš tako nešto verovatno bi to mogao da postigneš tako što ćeš tu funkciju u klasi B dodatno da proglasiš statičnom. Onda bi trebalo da se izvrši njen poziv. Naravno, to opet menja dizajn klase na neki način, a i dođe malo neprirodno da radiš tako nešto.
Ne sećam se da sam skoro probao tako nešto, ali vidi pa javi šta si uradio.
[ Mirko Rajkovača @ 27.12.2006. 10:28 ] @
Toga sam se bojao, totalno sam prevideo ovu stvar kada sam poceo sa
dizajniranjem klasa. Ipak stoji ona programerska prvo osmisli pa
kodiraj...:)
[ Goran Arandjelovic @ 27.12.2006. 14:19 ] @
Ipak, ono što sam ti pomenuo da uradiš nije moguće, tako da ti ostaje da na drugi način promeniš implementaciju.
[ 1jedini @ 27.12.2006. 16:18 ] @
ISO 14882 kaze:

10.4.6:
Member functions can be called from a constructor (or destructor) of an abstract class; the effect of making
a virtual call (10.3) to a pure virtual function directly or indirectly for the object being created (or
destroyed) from such a constructor (or destructor) is undefined.

12.7.3
Member functions, including virtual functions (10.3), can be called during construction or destruction
(12.6.2). When a virtual function is called directly or indirectly from a constructor (including from the
mem-initializer for a data member) or from a destructor, and the object to which the call applies is the
object under construction or destruction, the function called is the one defined in the constructor or
destructor’s own class or in one of its bases, but not a function overriding it in a class derived from the constructor
or destructor’s class, or overriding it in one of the other base classes of the most derived object (1.8).

If the virtual function call uses an explicit class member access (5.2.5) and the object-expression
refers to the object under construction or destruction but its type is neither the constructor or destructor’s
own class or one of its bases, the result of the call is undefined. [Example:
Code:

class V {
 public:
  virtual void f();
  virtual void g();
 };

class A : public virtual V {
 public:
  virtual void f();
 };
class B : public virtual V {
 public:
  virtual void g();
  B(V*, A*);
};
class D : public A, B {
 public:
  virtual void f();
  virtual void g();
  D() : B((A*)this, this) { }
};
 B::B(V* v, A* a) 
 {
  f(); //calls V::f, not A::f
  g(); //calls B::g, not D::g
  v->g(); // v is base of B, the call is well-defined, calls B::g
  a->f(); //undefined behavior, a’s type not a base of B
 }

—end example]
[ Mirko Rajkovača @ 27.12.2006. 17:50 ] @
Hvala vam svima na trudu, uspeo sam da resim problem momentalno zurim pa
nemam vremena da objasnim