Assigning variables to class

Jun 3, 2013 at 1:20am
Hi,

I feel like a noob for saying this, but how could you assign variables to a class, but not inside it? For example, you have an if statement that says if this is true, assign this variable to class foo. Please help!

Jun 3, 2013 at 1:49am
What do you mean by "assign"?
Usually we talk of assigning a value to a variable. For example,
1
2
    int x;  // define the variable x
    x = 5;  // assign the value 5 to variable x 


I've a feeling you mean something a bit different, but it's not clear what exactly.
Last edited on Jun 3, 2013 at 1:50am
Jun 3, 2013 at 2:19am
Like this:
 
         int classFoo::fooy = 88

Jun 3, 2013 at 2:27am
What would be the point of using a class like that? You should just use a public like this:
1
2
3
4
5
6
7
8
9
10
11
class Foo
{
public:
    int y;
}

int main()
{
    Foo f;
    f.y = 88;
}


Still kind of pointless to use a class like that I would suggest this:
1
2
3
int main()
{
    int y( 88 ); //initialize or -> int y; y = 88; <- to declare and then assign value 
Jun 3, 2013 at 2:37am
Thank u gilbit :)
Topic archived. No new replies allowed.