Current (this) object as a parameter?

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
53
amir_avatar 2015.08.10 13:16 #
 

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  

avatar
53
amir_avatar 2015.08.10 13:28 #
 

Sorry, I saw you did it just now.

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

  

avatar
6
mrtwister 2015.08.10 13:39 #
 

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 

avatar
53
amir_avatar 2015.08.10 14:58 #
 

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());
    }

};
 

avatar
6
mrtwister 2015.08.10 16:16 #
 

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! 

 

 

Back to topics list   | 1 2  

To add comments, please log in or register