Jump to content
  • Advertisement

Archived

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

Blaste

Simple class question

This topic is 5636 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

If a class is created using "new" then is its constructor used? If so, and if it is "delete"ed, then would I be safe to assume that it''s destructor is also used?

Share this post


Link to post
Share on other sites
Advertisement
Ok, now I have another question
When you create a class normally, cClass class, the constructor is called publicly, so if the constructer was private then it would cause an error, right? But when a class is created with new, it can call upon a private constructor? Sorry for the simple class questions, but I''m trying to decipher how singleton classes work the way they do. I prolly should have stated the full question in my first post. Thanks ahead of time.

Share this post


Link to post
Share on other sites
Also, a few more complicated class questions. Would a static function be able to call other functions in the class? And what would a static function class member do with a "this" pointer?

Share this post


Link to post
Share on other sites
If the constructor is private only a function in the class itself or a class or function declared as a friend can invoke the constructor. This is true for static or dynamic allocation.


  
class class1
{
private:
class1(){};

public:
static class1 * CreateFunc(){return new class1;};

friend class1 * FriendFunc();
};

class1 * FriendFunc()
{
return new class1;
}

int main()
{
class1 c1; // not allowed;

class1 *pc1; // pointer declaration is fine

pc1 = new class1; // not allowed;


pc1 = class1::CreateFunc(); // allowed

pc1 = FriendFunc(); // allowed

...
}


"That''s a very nice hat."
-Korben Dallas

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!