Current (this) object as a parameter? - page 2

 

you see the first

class object;

then definition of Container

and then definition of Object

I did not mean you switch the order of classes, just add the first statement  

 

Sorry, I saw you did it just now.

Try adding class Container; before Object and class Object before Container.

 

There is no difference :(

class Object;
class Container { ... };
class Object { ... };

errors in compiling.

also as:

class Container;
class Object { ... };
class Container { ... };

also as:

class Container;
class Object;

class Object { ... };
class Container { ... };

and if i swap las two lines :( 

Same if i use #includes 

 

Again, not by my pc but definetly done it a lot.
By reading again your code, you try to assign a wrong object type.

WhatIsYourContainer() returns Container* but you assign it to Object*
Change it and try again 

public:

    Object* object;
    double m_Price;

    Container(double price) { m_Price = price; }
    double getPrice(){ return m_Price; }

    void addObject() {
        object = new Object(GetPointer(this), m_Price);
        Object* obj = object.whatIsYourContainer();                    // object.WhatIsYourContainer returns Container and not object
        Print(obj.getPrice());
    }

};
 

 

Yeah! You was absolutely right :) also i have some buggy var name declarations in constructor parameters. Final code, for those who will be doing same stupid things as i do:

 

#property strict

class Object;

class Container {
public:
    Object* object;
    double m_Price;

    Container(double price) { m_Price = price; }
    double getPrice(){ return m_Price; }

    void addObject() {
        object = new Object(GetPointer(this), m_Price);
        Container* cont = object.whatIsYourContainer();
        Print("Objects container price is: "+(string)cont.getPrice());
    }

};

class Object {
public:
    double objectPrice;
    Container* cont;
    Object(Container* Cont, double Price) {
        objectPrice = Price;
        cont = Cont;
    }
    Container* whatIsYourContainer() {
        return cont;
    }
    double getPrice() {
      return objectPrice;
    }
};


int OnInit()
  {

Container* c = new Container(1.31200);
c.addObject();

return(INIT_SUCCEEDED);
  }

 Works well on build 840

Thanks man! 

Reason: