#include "shape.h"
..
other #includes with classes that are derived from shape.h
..
usingnamespace std;
..
function definition for addShape
..
int main()
{
init_graphics();
Shape *sar[50];
addShape(sar, MAX);
//wait 2 seconds then clear screen
wait(2000);
clear_screen();
_getch();
return 0;
}
But the code fails before it can even run, giving me only that error message. What am I doing wrong?
I was looking at some solutions and I found one you might use
Don't define Shape::Shape(){} in your header file but instead in shape.cpp
The header guards prevent a header from being included multiple times in the same translation unit, but each CPP file is (typically) a separate translation unit. So you end up with many definitions of Shape::Shape(){} - one for each CPP file where you include it (for example triangle.cpp)
#pragma once
#ifndef SHAPE_H
#define SHAPE_H
usingnamespace std;
class Shape {
public:
int posx;
int posy;
//Shape(int x, int y);
//virtual void print();
};
#endif