Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]-Pointers- When to use them

[SOLVED]-Pointers- When to use them

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 838 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paawan
    wrote on last edited by
    #1

    Hi All,

    Sorry for asking such trivial questions but need clear them for my exam.

    @
    Film* findFilm(QString id) const;
    @

    In the above statement the function is returning a pointer to the Film object. Am I correct?

    Why should we return pointers instead of objects? Is it to save memory?

    Thanks again.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leonardo.ramosantos
      wrote on last edited by
      #2

      Hi,

      Yes, that code will return a pointer.

      One of the situations where it's better to use pointers is when you need to pass objects between functions. If you pass a object instance as a parameter, the object memory area will be copied for each function that you use it. If you pass a pointer, just a pointer to the object memory area will be copied for the functions. In this way you will save memory and time.

      Another situation to use pointers is when you need to create dynamically objects. If you use variables of object, it can be destroyed at the end of the function whereas created.

      This subject can generate hours of conversation. This is just a overview of using pointers.

      []'s

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Paawan
        wrote on last edited by
        #3

        Thank you for the reply.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved