Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Allowing user to create an instance of class

This topic is 5721 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I''m new to OOP with C++ and wanted to make a simple database type program,in an attempt to get used to OOP. Anyway maybe i''ve missed something very simple but I haven''t come across a method to allow the user to make a new instance of a class, the only way im used to doing so is by writing it into the code. Thanks.

Share this post

Link to post
Share on other sites

ObjectManager->Add(new CObject);

or maybe

rawrr = new CObject;


or maybe I misunderstood the question...

Share this post

Link to post
Share on other sites
Create a dynamic array of the class type you want to let the user create. Then whenever , you enlarge the array by one element, and create the class-instance for that element...

Hope I''m clear.

Some sample-code in Delphi :

// First, declaration of a dynamic TMyClass array, where TMyClass
// is the name the name of the class.
var ArrayWithMyClass = Array of TMyClass;

// Here is a function declaration (in delphi called a procedure here)
// It is triggered when the user clicks a button.
procedure TForm1.Button1Click(Sender: TObject);
// The following line adds one element to our array
SetLength(ArrayWithMyClass, Length(ArrayWithMyClass) + 1);
// And now, we''ve got to create that element. The
// .create is similar to "new" in C++
ArrayWithMyClass[Length(ArrayWithMyClass) - 1] := TMyClass.Create;

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!