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 520965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:12:02+00:00 2026-05-13T08:12:02+00:00

since I’ve came from c# to c++ everything looks crazy for me in c++.

  • 0

since I’ve came from c# to c++ everything looks crazy for me in c++.
I just wondering If someone could explain me why do we have these kind of instantiating in c++ :
method 1:

ClassA obj1; // this is going to stack

method 2:

ClassA *obj1 = new ClassA(); //this is going to heap

whereas we don’t have the common instantiating in C# way on c++ :

ClassA  obj2 = new obj2();

and one more question in method1 I get an instance from the ClassA but without the () and this is the exact place the I’ve got confused , why do we have to instatiating like that?
our ClassA has an constructor but instantiating without parentheses???
how come we call its constructor?

p.s : I’ve read these topics :

Different methods for instantiating an object in C++

Stack, Static, and Heap in C++

What and where are the stack and heap?

  • 1 1 Answer
  • 0 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-13T08:12:02+00:00Added an answer on May 13, 2026 at 8:12 am

    Indeed moving to C++ from a language like Java or C# can be daunting, I’ve gone through it as well.

    The first and foremost difference is that in C++ you almost always manage your own memory. When creating an object on the heap you are responsible for deleting it so it does not leak memory – this in turn means you can delete it when you see fit. When creating an object on the stack, it is automatically deleted when it goes out of scope – you must be careful not to use it after it goes out of scope.

    Example:

    void do_queue(B& queue)
    {
        Evt *e = new Evt;
        queue.queueEvent(e); 
    } // all well, e can be popped and used (also must be deleted by someone else!)
    

    versus

    void do_queue(B& queue)
    {
        Evt e;
        queue.queueEvent(&e); 
    } // e is out of scope here, popping it from the queue and using it will most likely cause a sigseg
    

    That being said, the two methods are also significantly different in one aspect: the first one creates an object. The second one creates a pointer to an object. The nice thing about having pointers is that you can pass them around as parameters with only minimal memory being copied on the stack (the pointer is copied, instead of the whole object). Of course, you can always get the address of an object allocated on the stack by using “&”, or pass it around as a reference – however, when using objects allocated on the stack you much be especially careful with their scope.

    I’ve found this website a great resource when I moved from Java to C++: http://www.parashift.com/c++-faq-lite/ – you will probably find it too, it offers a lot of good explanations

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

Sidebar

Related Questions

Since python has way to do nearly everything I was wondering is there any
Since now I have only used plugin for editing and the way I use
Since input and raw_input() stop the program from running anymore, I want to use
Since I have no errors I don't know if this is the right place
Since in the control file I have to provide a name (hard-coded) I need
since they have same rendering engine, this problem shows in both. it works great
Since Javascript does not have any functionality by itself to communicate over raw sockets
Since installing xcode 4.3 (from the app store), Xcode crashes when I try to
Since trees are special kind of graphs or we can categorize trees in DAG(Directed
Since i have a complex hierarchy of views i handle the rotation manually with

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.