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.
Cire I love you !! thanks !