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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:59:19+00:00 2026-05-31T18:59:19+00:00

Will there be a difference between the following two ways of calling a function

  • 0

Will there be a difference between the following two ways of calling a function from an instance? Which is better?

    Motor M;
    M.moveToPosition(Speed, TargetPosition);

    Motor *M;
    M->moveToPosition(Speed, TargetPosition);

Thanks!

  • 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-31T18:59:20+00:00Added an answer on May 31, 2026 at 6:59 pm

    Your second version has Undefined Behavior, because the pointer is uninitialized!

    You can dynamically allocate an object of type Motor(i.e. allocate it on the heap):

    Motor *M = new Motor;
    M->moveToPosition(Speed, TargetPosition);
    ...
    delete M;
    

    Smart Pointers will help you avoid to have to remember to delete objects allocated on the heap.

    As for which is better, I am afraid it depends a lot on the context. Usually in C++ you should prefer automatic objects (on the stack) to dynamic objects (on the heap) unless you have a definite reason for the contrary.

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

Sidebar

Related Questions

From what I gather the following two will bring back the same result FB.api
Will there normally only be one instance of MainForm? I need to hold it
What is the difference between instantiating a Stream object, such as MemoryStream and calling
What is the difference between ${...} and !{...} in the Spark View Engine? There
A couple of questions actually, Given that the following two will return the same
I need to be able to compute differences between two data/time values which represent
Simple question, but one that I've been curious about...is there a functional difference between
I came across a difference in speed using the following two structs: public struct
I'm playing with a GWT/GAE project which will have three different pages, although it
Will there be any further resultset to process if the lookup table in the

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.