I'm having frustrations with C++... when I try and compile my code (as simplistic as it is), I keep getting a 'Shape' not declared error, but I'm fairly certain that I've written it correctly.

shape.h

#ifdef shape_h
#define shape_h

using namespace std;

class Shape {
    public:
        Shape();
        virtual ~Shape() = 0;
        virtual void draw() = 0;
};

class Square : public Shape
{
    public:
        Square();
        ~Square();
};
#endif

shape.cpp

#include "shape.h"
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

Shape::Shape() {}
Shape::~Shape() {}

Square::Square() {}

void Square::draw()
{
    glColor3f(1.0,0.0,0.0);
    glRectf(-0.5,-0.5,1.0,1.0);
}

error

shape.cpp:11: error: ‘Shape’ has not been declared
shape.cpp:11: error: ISO C++ forbids declaration of ‘Shape’ with no type
shape.cpp:12: error: expected constructor, destructor, or type conversion before ‘::’ token
shape.cpp:14: error: ‘Square’ has not been declared
shape.cpp:14: error: ISO C++ forbids declaration of ‘Square’ with no type
shape.cpp:16: error: ‘Square’ is not a class or namespace
shape.cpp: In function ‘int Shape()’:
shape.cpp:11: warning: control reaches end of non-void function
shape.cpp: In function ‘int Square()’:
shape.cpp:14: warning: control reaches end of non-void function
make: *** [shape.o] Error 1

any ideas?

At the top of your header, you have:

#ifdef shape_h
#define shape_h

that should really be ifndef . Why define it if it is already defined? ;)
Also, you don't have "draw" defined in your class definition for Square. Lastly... you are missing an int main :icon_eek:

Yeah....

silly Oops on my part. Thanks!

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.