C++ - Class doesn't work ... program won't compile.

997c9d13ec65af5652061bbb1f3f0a38
0
losslessgggs 101 Apr 28, 2012 at 05:32

First of all, I deeply, deeply, deeply hate object-oriented programming, but since every fucking thing requires it, I guess there’s no choice, and I’m basically about to quit programming altogether because I’m getting very sick of it.

This code won’t compile:

#include <iostream>
using namespace std;
class CR
{
    public:
    int cope;
};
int main()
{
    CR::cope = 20;
    return 0;
}

error: invalid use of non-static data member ‘CR::cope’

2 Replies

Please log in or register to post a reply.

8841398f11572878754ded03c22feb53
0
asvsfs 101 Apr 28, 2012 at 06:02

you cant access to non static member variable like that you should first make an instance from your class then use its members …

CR * myClass = new CR();
myClass->cope = 20;
or
CR myClass;
myClass.cope=20;

you should read before you start coding ,… and if you hate oop programming and hate reading you should quit at all

8676d29610e6c98d6dd2d9c38528cd9c
0
alphadog 101 May 01, 2012 at 20:32

If you hate OOP because it’s too hard, try Haskell or LISP. If that’s still too hard, try Malbodge.