I'm trying to declare a new shape Square and later will add a circle, to the same array Shape which is an abstract class.
I'm a bit confused since I'm not getting any errors but the program is just crashing (but works when the code is removed)
Main:
#include "Shape.h"
#include "Square.h"
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
Shape *shapesArray[6];
Square *s;
s->setValues(1.0f, 2.0f, 3.0f, 4.0f);
shapesArray[0] = s;
printf("hello world\n");
return 0;
}
Square.cpp:
#include "Square.h"
void Square::setValues(float w, float x, float y, float z){
this->w = w;
this->x = x;
this->y = y;
this->z = z;
}
Square.h:
#include "Shape.h"
using namespace std;
class Square: public Shape
{
float w,x,y,z;
public:
void setValues(float,float,float,float);
Square();
};
Shape.cpp
#include <iostream>
using namespace std;
// Base class
class Shape {
public:
// pure virtual function providing interface framework.
virtual int getArea() = 0;
Shape();
protected:
int radius;
float x;
float y;
float w;
float z;
};