2 Replies - 176 Views - Last Post: 08 July 2012 - 09:18 AM Rate Topic: -----

#1 Zilna  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 08-October 10

Non static member variable

Posted 08 July 2012 - 06:09 AM

I am supposed to continue on with my previous guessing game and include a non static member variable within a new class that stores the number and i've no clue how to even go about doing this. Does anyone perhaps have some sort of tutorial or sample code that I could look at to figure this out? I have tried www.cplusplus.com but am very sketchy on the idea and really do not understand at all.
Is This A Good Question/Topic? 0
  • +

Replies To: Non static member variable

#2 sepp2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1716
  • View blog
  • Posts: 2,594
  • Joined: 21-June 11

Re: Non static member variable

Posted 08 July 2012 - 06:15 AM

Your question is very unclear and non-specific, but here's an example of a class with a non-static member variable:


#include <iostream>

class MyClass {
private:
    int my_non_static_member_variable;

public:
    MyClass(int x) : my_non_static_member_variable(x)
    {
    }

    int get_my_non_static_member_variable() {
        return my_non_static-member_variable;
    }
};

int main() {
    MyClass my_object(42);
    std::cout << my_object.my_non_static_member_variable << std::endl;
    return 0;
}


Was This Post Helpful? 1
  • +
  • -

#3 Zilna  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 08-October 10

Re: Non static member variable

Posted 08 July 2012 - 09:18 AM

I know it was very nonspecific, and you provided me with some sort of example quite well .. thank you! I was trying not to ask for help with the work but more of just something that I could look at to figure it out on my own, and you provided me with that. Will get to work on my assignment and see how it comes out, thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1