Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. variable declaration dought

variable declaration dought

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structureshelp
3 Posts 2 Posters 0 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.
  • D Offline
    D Offline
    Deepu Antony
    wrote on last edited by
    #1

    Hi all I am having a C++ class and in that some functions are also there.One variable i want to use in a function only.So i can declare it inside that function or as a member variable. Variables declared in a function will be saved on the stack but what about member variables. Which way should be more efficient. Can anybody help me to show some good articles in good programming practices. Thanks and regards Deepu

    _ 1 Reply Last reply
    0
    • D Deepu Antony

      Hi all I am having a C++ class and in that some functions are also there.One variable i want to use in a function only.So i can declare it inside that function or as a member variable. Variables declared in a function will be saved on the stack but what about member variables. Which way should be more efficient. Can anybody help me to show some good articles in good programming practices. Thanks and regards Deepu

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Where member variables are stored will depend upon how the class is instantiated. If an object of the class is created on the stack, the member variables will also reside on the stack. If the object is created on the heap, the member variables will also reside on the heap. If a variable is used only within a function, you should declare it within that function itself. And if you want the value retained across function calls, then declare it static.

      «_Superman_» I love work. It gives me something to do between weekends.

      D 1 Reply Last reply
      0
      • _ _Superman_

        Where member variables are stored will depend upon how the class is instantiated. If an object of the class is created on the stack, the member variables will also reside on the stack. If the object is created on the heap, the member variables will also reside on the heap. If a variable is used only within a function, you should declare it within that function itself. And if you want the value retained across function calls, then declare it static.

        «_Superman_» I love work. It gives me something to do between weekends.

        D Offline
        D Offline
        Deepu Antony
        wrote on last edited by
        #3

        Thanks..

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups