Уже в который раз встречаю ошибки LNK2019, LNK2001, LNK1120.
main.cpp
#include <iostream>
#include <cmath>
using namespace std;
#include "Kilometer.h"
#include "Meter.h"
#include "Decimeter.h"
#include "Centimeter.h"
#define MAX 10
int main() {
Kilometer* arr[MAX]; //масив покажчиків на базовий клас
for (int i = 0; i < MAX; i++) { arr[i] = NULL; } //обнулення масиву
for (int i = 0; i < MAX; i++)
{
if (i % 3 == 0 || i % 3 == 1 || i % 3 == 2) {
arr[i] = new Centimeter(1 + rand() % MAX);
} else if (i % 3 == 3 || i % 3 == 4 || i % 3 == 5 || i%3 == 10)
arr[i] = new Decimeter(1 + rand() % MAX);
else if (i % 3 == 6 || i % 3 == 7 || i % 3 == 8 || i% 3 == 9 )
arr[i] = new Meter(1 + rand() % MAX);
arr[i] -> Square();
arr[i] -> Out(); //виклик методів для елементів масиву
}
for( int i = 0; i < MAX; i++ )
if( arr[i] ) delete arr[i]; //очищення масиву
return 0;
}
Kilometer.h
#pragma once
class Kilometer{
protected:
double length;
public:
Kilometer (double length=0);
virtual ~Kilometer () = 0;
virtual void Out() = 0;
virtual double Square() = 0;
}
;
Meter.h
#pragma once
#include "Kilometer.h"
class Meter: public Kilometer{
public:
Meter(double length);
~Meter() ;
double Square();
void Out();
}
;
Decimeter.h
#pragma once
#include "Kilometer.h"
class Decimeter: public Kilometer{
public:
Decimeter(double length);
~Decimeter();
double Square();
void Out();
};
Centimeter.h
#pragma once
#include "Kilometer.h"
class Centimeter: public Kilometer{
public:
Centimeter(double length);
~Centimeter();
double Square();
void Out();
};
Kilometer.cpp
#include "Kilometer.h"
#include <iostream>
using namespace std;
Kilometer::Kilometer(double length) {
this->length = length;
}
Meter.cpp
#include <iostream>
#include "Meter.h"
using namespace std;
Meter::Meter(double length) : Kilometer(length)
{
this->length = length;
}
Meter::~Meter(){}
double Meter::Square()
{
return length * 1000 * 1000;
}
void Meter::Out()
{
cout<<"the square area in meters is :\t"<<Square()<<endl;
}
Decimeter.cpp
```
#include #include "Decimeter.h" using namespace std;
Decimeter::Decimeter(double length) : Kilometer(length)
{
this->length = length;
}
Decimeter::~Decimeter(){}
double Decimeter::Square()
{
return length * 10000 * 10000;
}
void Decimeter::Out()
{
cout<<"the square area in decimeters is :\t"<<Square()<<endl;
}
Centimeter.cpp
#include <iostream>
#include "Centimeter.h"
using namespace std;
Centimeter::Centimeter(double length) : Kilometer(length)
{
this->length = length;
}
Centimeter::~Centimeter(){};
double Centimeter::Square()
{
return length * 100000 * 100000;
}
void Centimeter::Out()
{
cout<<"the square area in centimeters is :\t"<<Square()<<endl;
}

.. = default ;- короче и быстрее. – AlexGlebe Jun 10 '21 at 09:26