LNK2019/"L buffer is too small"
Есть проект, в котором: Software - абстрактный класс Software.h
#pragma once
#include <iostream>
#include <cstring>
using namespace std;
class Software {
public:
char name[64];
char type[64];
char author[64];
int size;
Software();
Software(const char* name, const char* type, const char* author, int size);
Software(const Software& other);
~Software();
void setName(const char* name);
const char* getName() const;
void setType(const char* type);
const char* getType() const;
void setAuthor(const char* author);
const char* getAuthor() const;
void setSize(int size);
int getSize() const;
virtual void print() const = 0;
Software& operator=(const Software& other);
};
Software.cpp
#include "Software.h"
#include <iostream>
#include <cstring>
using namespace std;
Software::Software() : size(0) {
name[0] = '\0';
type[0] = '\0';
author[0] = '\0';
}
Software::Software(const char* name, const char* type, const char* author, int size)
: size(size) {
strncpy_s(this->name, name, sizeof(this->name));
this->name[sizeof(this->name) - 1] = '\0';
strncpy_s(this->type, type, sizeof(this->type));
this->type[sizeof(this->type) - 1] = '\0';
strncpy_s(this->author, author, sizeof(this->author));
this->author[sizeof(this->author) - 1] = '\0';
}
Software::Software(const Software& other) {
strncpy_s(name, other.name, sizeof(name));
name[sizeof(name) - 1] = '\0';
strncpy_s(type, other.type, sizeof(type));
type[sizeof(type) - 1] = '\0';
strncpy_s(author, other.author, sizeof(author));
author[sizeof(author) - 1] = '\0';
size = other.size;
}
Software::~Software() {
}
void Software::setName(const char* name) {
strncpy_s(this->name, name, sizeof(this->name));
this->name[sizeof(this->name) - 1] = '\0';
}
const char* Software::getName() const {
return name;
}
void Software::setType(const char* type) {
strncpy_s(this->type, type, sizeof(this->type));
this->type[sizeof(this->type) - 1] = '\0';
}
const char* Software::getType() const {
return type;
}
void Software::setAuthor(const char* author) {
strncpy_s(this->author, author, sizeof(this->author));
this->author[sizeof(this->author) - 1] = '\0';
}
const char* Software::getAuthor() const {
return author;
}
void Software::setSize(int size) {
this->size = size;
}
int Software::getSize() const {
return size;
}
Software& Software::operator=(const Software& other) {
if (this != &other) {
strncpy_s(name, other.name, sizeof(name));
name[sizeof(name) - 1] = '\0';
strncpy_s(type, other.type, sizeof(type));
type[sizeof(type) - 1] = '\0';
strncpy_s(author, other.author, sizeof(author));
author[sizeof(author) - 1] = '\0';
size = other.size;
}
return *this;
}
наследуемые от него классы GR, OS, SR. GR.h
#pragma once
#include "Software.h"
#include <cstring>
class GR : Software {
public:
char os[100];
GR();
GR(const char* name, const char* type, const char* author, int size, const char* os);
GR(const GR& othergr);
void print() const override;
const char* getos() const;
void setos(const char* GR);
GR& operator=(const GR& othergr);
};
GR.cpp
#include "GR.h"
#include <cstring>
using namespace std;
GR::GR() {
os[0] = '\0';
}
GR::GR(const char* name, const char* type, const char* author, int size, const char* os) : Software(name, type, author, size) {
strncpy_s(this->os, os, sizeof(this->os));
this->os[sizeof(this->os) - 1] = '\0';
}
GR::GR(const GR& othergr) : Software(name, type, author, size) {
strncpy_s(os, othergr.os, sizeof(os));
os[sizeof(os) - 1] = '\0';
}
void GR::print() const {
cout << "Name: " << GR::name << endl << "Type: " << GR::type << endl << "Author: " << GR::author << endl << "OS: " << GR::os << endl;
}
const char* GR::getos() const {
return os;
}
void GR::setos(const char* GR) {
strncpy_s(this->os, os, sizeof(this->os));
this->os[sizeof(this->os) - 1] = '\0';
}
GR& GR::operator=(const GR& othergr) {
if (this != &othergr) {
strncpy_s(name, othergr.name, sizeof(name));
name[sizeof(name) - 1] = '\0';
strncpy_s(type, othergr.type, sizeof(type));
type[sizeof(type) - 1] = '\0';
strncpy_s(author, othergr.author, sizeof(author));
author[sizeof(author) - 1] = '\0';
size = othergr.size;
strncpy_s(os, othergr.os, sizeof(os));
os[sizeof(os) - 1] = '\0';
}
return *this;
}
SR.h
#pragma once
#include "Software.h"
#include <cstring>
class SR : Software {
public:
char PL[100];
SR();
SR(const char* name, const char* type, const char* author, int size, const char* PL);
SR(const SR& othersr);
void print() const override;
const char* getPL() const;
void setPL(const char* PL);
SR& operator=(const SR& othersr);
};
SR.cpp
#include "SR.h"
#include <cstring>
using namespace std;
SR::SR() {
PL[0] = '\0';
}
SR::SR(const char* name, const char* type, const char* author, int size, const char* PL) : Software(name, type, author, size) {
strncpy_s(this->PL, PL, sizeof(this->PL));
this->PL[sizeof(this->PL) - 1] = '\0';
}
SR::SR(const SR& othersr) : Software(name, type, author, size) {
strncpy_s(PL, othersr.PL, sizeof(PL));
PL[sizeof(PL) - 1] = '\0';
}
void SR::print() const
{
cout << "Name: " << SR::name << endl << "Type: " << SR::type << endl << "Author: " << SR::author << endl << "Size: " << SR::size << endl << "Programming language: " << SR::PL << endl;
}
const char* SR::getPL() const
{
return PL;
}
void SR::setPL(const char* PL)
{
strncpy_s(this->PL, PL, sizeof(this->PL));
this->PL[sizeof(this->PL) - 1] = '\0';
}
SR& SR::operator=(const SR& othersr) {
if (this != &othersr) {
strncpy_s(name, othersr.name, sizeof(name));
name[sizeof(name) - 1] = '\0';
strncpy_s(type, othersr.type, sizeof(type));
type[sizeof(type) - 1] = '\0';
strncpy_s(author, othersr.author, sizeof(author));
author[sizeof(author) - 1] = '\0';
size = othersr.size;
strncpy_s(PL, othersr.PL, sizeof(PL));
PL[sizeof(PL) - 1] = '\0';
}
return *this;
}
OS.h
#pragma once
#include "Software.h"
#include <cstring>
class OS : Software {
public:
char arch[100];
OS();
OS(const char* name, const char* type, const char* author, int size, const char* arch);
OS(const OS& otheros);
void print() const override;
const char* getarch() const;
void setarch(const char* OS);
OS& operator=(const OS& otheros);
};
OS.cpp
#include "OS.h"
#include <cstring>
using namespace std;
OS::OS() {
arch[0] = '\0';
}
OS::OS(const char* name, const char* type, const char* author, int size, const char* arch) : Software(name, type, author, size) {
strncpy_s(this->arch, arch, sizeof(this->arch));
this->arch[sizeof(this->arch) - 1] = '\0';
}
OS::OS(const OS& otheros) : Software(name, type, author, size) {
strncpy_s(arch, otheros.arch, sizeof(arch));
arch[sizeof(arch) - 1] = '\0';
}
void OS::print() const {
cout << "Name: " << OS::name << endl << "Type: " << OS::type << endl << "Author: " << OS::author << endl << "Size: " << OS::size << endl << "Arch: " << OS::arch << endl;
}
const char* OS::getarch() const {
return arch;
}
void OS::setarch(const char* OS) {
strncpy_s(this->arch, arch, sizeof(this->arch));
this->arch[sizeof(this->arch) - 1] = '\0';
}
OS& OS::operator=(const OS& otheros) {
if (this != &otheros) {
strncpy_s(name, otheros.name, sizeof(name));
name[sizeof(name) - 1] = '\0';
strncpy_s(type, otheros.type, sizeof(type));
type[sizeof(type) - 1] = '\0';
strncpy_s(author, otheros.author, sizeof(author));
author[sizeof(author) - 1] = '\0';
size = otheros.size;
strncpy_s(arch, otheros.arch, sizeof(arch));
arch[sizeof(arch) - 1] = '\0';
}
return *this;
}
и шаблонный класс Queue. Queue.h
#pragma once
#include <iostream>
#include <queue>
template <class T>
class Queue {
private:
std::queue<T> elements;
public:
Queue();
Queue(const T& element);
Queue(const Queue<T>& other);
~Queue();
Queue<T>& operator=(const Queue<T>& other);
size_t size();
void push(const T& element);
void pop();
T top();
void clear();
bool isEmpty();
void print();
};
Queue.cpp
#include <iostream>
#include <queue>
#include "Queue.h"
using namespace std;
template <class T>
Queue<T>::Queue() {}
template <class T>
Queue<T>::Queue(const T& element) {
elements.push(element);
}
template <class T>
Queue<T>::Queue(const Queue<T>& other) {
elements = other.elements;
}
template <class T>
Queue<T>::~Queue() {}
template <class T>
void Queue<T>::push(const T& element) {
elements.push(element);
}
template <class T>
void Queue<T>::pop() {
if (!elements.empty()) {
elements.pop();
}
else {
std::cout << "Queue is empty, cannot pop." << std::endl;
}
}
template <class T>
T Queue<T>::top() {
if (!elements.empty()) {
elements.front().print();
}
else {
std::cout << "Queue is empty, returning default value." << std::endl;
return T();
}
}
template <class T>
void Queue<T>::clear() {
while (!elements.empty()) {
elements.pop();
}
}
template <class T>
bool Queue<T>::isEmpty() {
return elements.empty();
}
template <class T>
size_t Queue<T>::size() {
return elements.size();
}
template <class T>
Queue<T>& Queue<T>::operator=(const Queue<T>& other) {
if (this != &other) {
elements = other.elements;
}
return *this;
}
template <class T>
void Queue<T>::print() {
queue<T> temp = elements;
while (!temp.empty()) {
temp.front().print();
temp.pop();
}
cout << endl;
}
Я добавил в очередь объект класса SR(с остальными также) и хочу его вывести, но программа не запускается и в списке ошибок мне выдаёт это: "LNK2019 ссылка на неразрешенный внешний символ "public: __cdecl Queue::Queue(void)" (??0?$Queue@VGR@@@@QEAA@XZ) в функции main." и ещё 3 таких же ошибки, но с деструктором и методами push и print. При реализации очереди в одном файле открывается консоль и появляется окно с ошибкой: "L Buffer is too small && 0". Подскажите в чём проблема?