Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 903591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:54:28+00:00 2026-05-15T15:54:28+00:00

I have a class that has only one function Print() and two properties age,

  • 0

I have a class that has only one function “Print()” and two properties “age, sex”. And i am trying to understand when is object creating on memory?

i can always access to object’s props and functions even i didn’t call it’s constructor function.

Isn’t there any rule for the creating object from the class?

In C# this won’t create object on memory: ClassName cls;
But this will create: ClassName cls = new ClassName();
In C++ is there any way to not create object in memory until i need to call it’s constructor function?

#include <QtCore/QCoreApplication>
#include "iostream"

using namespace std;

class ClassName{
public:
    void print(){
        cout<< "Age: " <<age <<endl;
        cout<< "Sex: " <<sex <<endl;
    }
    int age;
    char sex;


};


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    ClassName *ex1 = new ClassName();
    ex1->print();

    ClassName ex2;
    ex2.print();

    ClassName ex3= {10,'e'};
    ex3.print();

    ClassName exCopy(ex3);
    exCopy.print();

    return a.exec();
}
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:54:29+00:00Added an answer on May 15, 2026 at 3:54 pm

    In C# this willn’t create object on memory: ClassName cls; But this will create: ClassName cls = new ClassName(); In C++ is there any way to not create object in memory until i need to call it’s constructor function?

    The equivalent to your C# example, using C++, is as follows:

    //pointer to ClassName, not initialized
    ClassName* cls1;
    //alternatively
    ClassName* cls2 = 0;
    //initialize after declaring it but before using it
    cls1 = new ClassName();
    cls1->print();
    //after initializing it, don't forget to delete it again later
    delete cls1;
    cls1 = 0;
    //this is an error (using uninitialized pointer)
    cls2->print();
    

    C# classes are ‘reference’ types, which are like C++ ‘pointer’ types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First of all, it's a really bad idea to use… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer If you are not dead set on using a listbox,… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer killproc will terminate programs in the process list which match… May 16, 2026 at 9:17 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have two classes, Car and Person. Car has as one of its members
Let's say we have a class that looks like this: class A { public:
I've got a script that calls two functions, A and B, from the same
Objective-C has no namespaces; it's much like C, everything is within one global namespace.
I am in a web scripting class and our teacher is very strict on
I'm using two different libraries in my project, and both of them supply a
By common script startup sequence, what I mean is that in the majority of
I have a parent thread (non-UI) which creates some child threads to do some
For the current app I am writing I have elected to place all database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.