Results 1 to 5 of 5

Thread: Calling other constructor ok?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Calling other constructor ok?

    Assume i have class A (fictional code)
    Code:
    type
      TClassA = class
      public
        constructor Create(width, height: integer);
        constructor Create;
        // Seems to compile fine without adding word "overload"
      end;
    
    implementation
    
    constructor TClassA.Create(width, height: integer);
    begin
      DoSomething(width, height);
    end;
    
    constructor TClassA.Create;
    begin
      Create(100, 100);
      // Now what happens here? Am i creating an object that will not get
      // assigned to any variable, basically a memory leak?
    end;
    How should i call the other constructor to refer self as its object? If there's a reserved word for this i don't know. "inherited" won't do as this case is not a parent class constructor.

    edit: Well, my class seems to work with this technique so i suppose its all ok... It was a class for FrameBuffer, rendering to texture and showing that on screen works

    Code:
    constructor Create(const _texture: integer; _depth: boolean = false);
    
    // This calls above Create with a newly created empty texture
    constructor Create(const width, height: integer; transparency: boolean; _depth: boolean = false);
    Edit2:
    So what i guess is happening is that there is a world of difference with Object.Create and Class.Create. Object.Create will not allocate a new object but instead uses it as a normal procedure. Right?
    Last edited by User137; 05-08-2011 at 03:10 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •