Assigning variables to class

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!

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
Like this:
 
         int classFoo::fooy = 88

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 
Thank u gilbit :)
Topic archived. No new replies allowed.