I do not understand why this program is not working. I'm new to C++, switching after three years of Java. I thought the error messages in Java made no sense but the errors I've been getting in C++ have been just straight gibberish. This is one I can actually understand.
Anyway so I have a program that has a Rectangle and Square Class. The square class inherits from the rectangle class. All my classes are all in different files.
================================(main)
#include <iostream>
#include "Rectangle.h"
#include "Square.h"
using namespace std;
int main(){
Square sq;
}//end main
================================(Rectangle.h)
#ifndef RECTANGLE_H
#define RECTANGLE_H
class Rectangle{
public:
Rectangle (int, int);
void setLength (int);
void setWidth (int);
int getLength ();
int getWidth ();
int getArea ();
private:
int length;
int width;
};
#endif // RECTANGLE_H
=================================(Rectangle.cpp)
#include <iostream>
#include "Rectangle.h"
#include "Square.h"
using namespace std;
Rectangle :: Rectangle (int len, int wid){
length = len;
width = wid;
}//end constructor
void Rectangle :: setLength (int l){
length = l;
}//end setLength
void Rectangle :: setWidth (int w){
width = w;
}//end setWidth
int Rectangle :: getLength (){
return length;
}//end getLength
int Rectangle :: getWidth (){
return width;
}//end getWidth
int Rectangle :: getArea (){
return length * width;
}//end getArea
========================================(Square.h)
#ifndef SQUARE_H
#define SQUARE_H
class Square : public Rectangle
{
public:
Square();
};
#endif // SQUARE_H
====================================(Square.cpp)
#include <iostream>
#include "Rectangle.h"
#include "Square.h"
using namespace std;
Square :: Square {
//super :: Square(4, 3);
cout << "This is bullshit";
};
=======================================================
super
keyword. It uses constructor initialization lists to initialize things (unless you count in-class member initialization, introduced in C++11). – chris Jun 11 at 3:59