Jump to content


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


2 replies to this topic

#1 losslegs

    New Member

  • Members
  • Pip
  • 1 posts

Posted 28 April 2012 - 05:32 AM

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;
}

Quote

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


#2 asvsfs

    New Member

  • Members
  • Pip
  • 4 posts

Posted 28 April 2012 - 06:02 AM

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

#3 alphadog

    DevMaster Staff

  • Moderators
  • 1716 posts

Posted 01 May 2012 - 08:32 PM

If you hate OOP because it's too hard, try Haskell or LISP. If that's still too hard, try Malbodge.
Hyperbole is, like, the absolute best, most wonderful thing ever! However, you'd be an idiot to not think dogmatism is always bad.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users