I'm just diving back into C++ after a while of being away. I've created a simple project. But its giving me these stupid errors when I've been trying to do some OOP:

main.cpp

#include <iostream>
using namespace std;

#include "oopy.h"

int main(int argc, char** argv)
{
	Oopy awesome;
	cout << "Look at this:\n";
	awesome = new Oopy();
	awesome->printIt();
	return 0;
}

oopy.cpp

#include <iostream>
using namespace std;

include "oopy.h"

Oopy::Oopy() {
	tenFingers= 10;
}

Oopy::~Oopy() {
	
}

oopy::printIt() {
	cout << "You have " << tenFingers << " fingers" << endl;
}

oopy.h

#ifndef _OOPY_H_
#define _OOPY_H_

class oopy {
	public:
		oopy();
		~oopy();
		void printIt();
	private:
		int tenFingers;
}

#endif

Pretty simple stuff, right? Well when I try to compile it with G++, I get the following error:

main.cpp:6: error: new types may not be defined in a return type
main.cpp:6: note: (perhaps a semicolon is missing after the definition of ‘oopy’)
main.cpp:6: error: two or more data types in declaration of ‘main’

I can't figure it out. Any help?

Class awsome is not a pointer you don't use -> .

Oopy.cpp missing something on the include?

Your class is missing a semicolon to finish it.

Did the changes that you suggested, and now I have a whole new set of errors. :(

Is there some simple example OOP stuff I can look at? Everything I google isn't included in an .h file, and if it is theres no .cpp file to go along with it.

Missing ';' symbol..

class oopy
{
   //...
}; // <- this line...

And replace

Oopy::Oopy()
{...}

with this..

oopy::oopy()
{...}
// and so on

Ah, turns out I wasn't compiling it properly, I needed to include the .o file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.