Получаю исключение wntdll.pdb not loaded
Здраствуйте, я столкнулся с исключением wntdll.pdb not loaded и мусором после операции сложения двух комплексных массивов.
Я полагаю, что проблема кроется в деструкторе, однако мне не хватает опыта, чтобы понять, что именно не верно.
Program.cpp
#include "ArrayOfComplex.h"
int main()
{
Complex c1, c2, c3;
cout << endl << "---------- ArrayOfComplex objects" << endl;
cout << "Enter three complex numbers (format: real imaginary):" << endl;
cin >> c1 >> c2 >> c3;
cout << "c1 = " << c1 << " , c2 = " << c2 << " , c3 = " << c3 << endl;
Complex ar1[] = { c1, c2, c3 };
Complex ar2[] = { c3, c2, c1 };
ArrayOfComplex ArObj1(3, ar1);
ArrayOfComplex ArObj2(3, ar2);
cout << "ArrayOfComplex ArObj1:" << endl << ArObj1;
cout << "ArrayOfComplex ArObj2:" << endl << ArObj2;
ArrayOfComplex ArObj3 = ArObj1 + ArObj2;
ArrayOfComplex ArObj4 = ArObj1 - ArObj2;
cout << "ArObj1 + ArObj2:" << endl << ArObj3;
cout << "ArObj1 - ArObj2:" << endl << ArObj4;
cout << "ArObj1[0] = " << ArObj1[0] << endl;
ArrayOfComplex ArObj5;
ArObj5 = ArObj1;
cout << "ArObj5 (after assignment from ArObj1):" << endl << ArObj5;
cout << "ArObj1 == ArObj2: " << (ArObj1 == ArObj2 ? "True" : "False") << endl;
cout << "ArObj1 != ArObj2: " << (ArObj1 != ArObj2 ? "True" : "False") << endl;
return 0;
}
Complex.h
#pragma once
#include <iostream>
using namespace std;
class Complex
{
float real;
float imaginary;
public:
// Constructors
Complex();
Complex(float real, float imaginary);
Complex(const Complex& other);
~Complex();
//Getters
float getReal() const;
float getImaginary() const;
// Operator overloading
Complex& operator=(const Complex& other);
bool operator==(const Complex& other) const;
bool operator!=(const Complex& other) const;
Complex operator+(const Complex& other) const;
Complex operator-(const Complex& other) const;
Complex operator*(const Complex& other) const;
Complex operator/(const Complex& other) const;
// Friend functions for stream operators
friend ostream& operator<<(ostream& os, const Complex& number);
friend istream& operator>>(istream& is, Complex& number);
};
Complex.cpp
#include "Complex.h"
Complex::Complex() : real(0.0), imaginary(0.0) {}
Complex::Complex(float real, float imaginary) : real(real), imaginary(imaginary) {}
Complex::Complex(const Complex& other) {
this->real = other.real;
this->imaginary = other.imaginary;
}
Complex::~Complex()
{
}
float Complex::getReal() const
{
return real;
}
float Complex::getImaginary() const
{
return imaginary;
}
Complex& Complex::operator=(const Complex& other) {
if (this != &other) {
real = other.real;
imaginary = other.imaginary;
}
return *this;
}
bool Complex::operator==(const Complex& other) const
{
return real == other.real && imaginary == other.imaginary;
}
bool Complex::operator!=(const Complex& other) const
{
return !(*this == other);
}
Complex Complex::operator+(const Complex& other) const{
return Complex(real + other.real, imaginary + other.imaginary);
}
Complex Complex::operator-(const Complex& other) const{
return Complex(real - other.real, imaginary - other.imaginary);
}
Complex Complex::operator*(const Complex& other) const{
return Complex(real * other.real - imaginary * other.imaginary,
real * other.imaginary + imaginary * other.real);
}
Complex Complex::operator/(const Complex& other) const{
float denominator = other.real * other.real + other.imaginary * other.imaginary;
return Complex((real * other.real + imaginary * other.imaginary) / denominator,
(imaginary * other.real - real * other.imaginary) / denominator);
}
ostream& operator<<(ostream& os, const Complex& number)
{
os << number.real << " + " << number.imaginary<<"*i";
return os;
}
istream& operator>>(istream& is, Complex& number) {
is >> number.real >> number.imaginary;
return is;
}
ArrayOfComplex.h
#pragma once
#include "Complex.h"
class ArrayOfComplex
{
unsigned int size;
Complex* pComplex;
public:
ArrayOfComplex();
ArrayOfComplex(int size);
ArrayOfComplex(int size, const Complex * complexArr);
~ArrayOfComplex();
bool operator==(const ArrayOfComplex& other) const;
bool operator!=(const ArrayOfComplex& other) const;
ArrayOfComplex& operator=(const ArrayOfComplex& other);
ArrayOfComplex operator+(const ArrayOfComplex& other) const;
ArrayOfComplex operator-(const ArrayOfComplex& other) const;
ArrayOfComplex operator*(const ArrayOfComplex& other) const;
ArrayOfComplex operator/(const ArrayOfComplex& other) const;
Complex& operator[](int i) const;
friend ostream& operator<<(ostream& os, const ArrayOfComplex& cArray);
friend istream& operator>>(istream& is, ArrayOfComplex& cArray);
};
ArrayOfComplex.cpp
#include "ArrayOfComplex.h"
ArrayOfComplex::ArrayOfComplex() : size(0), pComplex(nullptr){
std::cout << "Default constructor called\n";
}
ArrayOfComplex::ArrayOfComplex(int size) : size(size), pComplex(new Complex[size]) {
std::cout << "Parameterized constructor called\n";
}
ArrayOfComplex::ArrayOfComplex(int size, const Complex * complexArr) : size(size), pComplex(new Complex[size])
{
std::cout << "Copy constructor called\n";
for (int i = 0; i < size; i++)
pComplex[i] = Complex(complexArr[i]);
}
ArrayOfComplex::~ArrayOfComplex() {
std::cout << "Destructor called\n";
if(pComplex != nullptr)
delete[] pComplex;
}
bool ArrayOfComplex::operator==(const ArrayOfComplex& other) const
{
if (size != other.size) return false;
for (int i = 0; i < size; i++)
if (pComplex[i] != other.pComplex[i]) return false;
return true;
}
bool ArrayOfComplex::operator!=(const ArrayOfComplex& other) const
{
return !(*this == other);
}
ArrayOfComplex& ArrayOfComplex::operator=(const ArrayOfComplex& other)
{
std::cout << "Assignment operator called\n";
if (*this != other) {
if (this->pComplex != nullptr)
delete[] pComplex;
size = other.size;
pComplex = new Complex[size];
for (int i = 0; i < size; i++)
pComplex[i] = other.pComplex[i];
}
return *this;
}
ArrayOfComplex ArrayOfComplex::operator+(const ArrayOfComplex & other) const
{
std::cout << "Addition operator called\n";
int i;
ArrayOfComplex res((this->size >= other.size) ? this->size : other.size);
for (i = 0; i < this->size && i < other.size; i++)
res[i] = (*this)[i] + other[i];
for (; i < this->size; i++)
res[i] = (*this)[i];
for (; i < other.size; i++)
res[i] = other[i];
return res;
}
ArrayOfComplex ArrayOfComplex::operator-(const ArrayOfComplex& other) const
{
int i;
ArrayOfComplex res((this->size >= other.size) ? this->size : other.size);
for (i = 0; i < this->size && i < other.size; i++) {
res[i] = (*this)[i] - other[i];
}
for (; i < this->size; i++) {
res[i] = (*this)[i];
}
for (; i < other.size; i++) {
res[i] = other[i];
}
return res;
}
ArrayOfComplex ArrayOfComplex::operator*(const ArrayOfComplex& other) const
{
int i;
ArrayOfComplex res((this->size >= other.size) ? this->size : other.size);
for (i = 0; i < this->size && i < other.size; i++) {
res[i] = (*this)[i] * other[i];
}
for (; i < this->size; i++) {
res[i] = (*this)[i];
}
for (; i < other.size; i++) {
res[i] = other[i];
}
return res;
}
ArrayOfComplex ArrayOfComplex::operator/(const ArrayOfComplex& other) const
{
int i;
ArrayOfComplex res((this->size>=other.size)?this->size:other.size);
for (i = 0; i < this->size && i < other.size; i++) {
if(other[i].getReal() != 0 || other[i].getImaginary() != 0)
res[i] = (*this)[i] / other[i];
}
for (; i < this->size; i++) {
res[i] = (*this)[i];
}
for (; i < other.size; i++) {
res[i] = other[i];
}
return res;
}
ostream& operator<<(ostream& os, const ArrayOfComplex& cArray)
{
os <<"Size: " << cArray.size << endl;
for (int i = 0; i < cArray.size; i++) {
os << cArray.pComplex[i]<<endl;
}
return os;
}
istream& operator>>(istream& is, ArrayOfComplex& cArray)
{
cout << "Please enter the size: ";
is >> cArray.size;
cArray.pComplex = new Complex[cArray.size];
for (int i = 0; i < cArray.size; i++) {
cin >> cArray.pComplex[i];
}
return is;
}
Complex& ArrayOfComplex::operator[](int i) const
{
if (i < 0 || size <= i)
{
cout << "Index out of range!" << endl;
exit(1);
}
return pComplex[i];
}
Спасибо за любую помощь:)