Static Variables

Hello everyone,

I've got a problem with my programm.

I need to define a class I to have an output 1,2,3. I must use static variables.
main() function must be as follow:

int main()
{
I i,j,k;

cout << i++ <<",";
cout << j++ <<",";
cout << k++;

return 0;
}

I write below the programm I made, but he prints an empty output (,,).
I hope you can help me. Thanks.

#include <cstdlib>
#include <iostream>

using namespace std;

class I
{
public:
I(){
i+=1;
j+=i;
k+=j;
};

static int i,j,k;

I operator=(I w){return w;};
I operator++(int){};

~I(){};
};


int I::i=0;
int I::j=0;
int I::k=0;

std::ostream& operator<<(std::ostream &strm, const I &i)
{
return strm;
};

int main(int argc, char *argv[])
{
I i,j,k;

cout << i++ <<",";
cout << j++ <<",";
cout << k++;

return 0;
}


You have an empty operator++.

And your code is almost illegible.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

class I
{
public:
    int operator++(int) { return value++; }

private:
    static int value;
};

int I::value = 1;

using std::cout;
int main()
{
    I i, j, k;

    cout << i++ << ",";
    cout << j++ << ",";
    cout << k++;

    return 0;
}
Cire I love you !! thanks !
Topic archived. No new replies allowed.