class ctry
{
public:
int x=12;
};
If you try to assign a value to something in a class the compiler will think you want it to be pure which is only allowed for functions. Even then you should also get an error that only =0 is allowed as a pure specifier. What you want to do is provide a constructor that assigns the value to x when the object is created.
Code:
#include <iostream>
using namespace std;
class ctry
{
public:
ctry(){ x = 12; };
int x;
};
int main()
{
ctry test1;
cout << test1.x << "\n";
return 0;
}