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.
Non static member variable
Page 1 of 12 Replies - 176 Views - Last Post: 08 July 2012 - 09:18 AM
Replies To: Non static member variable
#2
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;
}
#3
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.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|