I'm creating a small library for several geometric shapes. Doing so, I'm writing down prototypes into a shapes.h
file and the methods into a shapes.cpp
file.
This is the header:
#ifndef __shapeslib
#define __shapeslib
class Shape{
protected:
struct dimensions{
double heigth;
double width;
};
double radius; // for circle class to be inherited
public:
Shape(double heigth, double width); // Constructor
Shape(const Shape & shape); // copy constructor for class
~Shape(); // Destructor
virtual double area(double heigth, double width);
virtual double perimeter(double heigth, double width);
void height();
void width();
double rotate(double heigth, double width);
};
But when saving the file in Atom software, I get these two errors for the line class Shape{
unknown type name 'class'
expected ';' after top level declarator
I read here that could be because I'm compiling in C rather than C++. I sincerely have no idea about how to avoid this (still a beginner).
I also tried to change the file name from .h
to .hpp
and seems working. Unfortunately, I must have a .h
header file.
Any feedback is really appreciated.
Thanks everyone.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…