R
R
rybic2021-07-01 17:15:33
C++ / C#
rybic, 2021-07-01 17:15:33

Why isn't the assignment operator overloaded (the program doesn't even run)?

main.cpp:

#define __CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#include "classic.h"
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#include <iostream>
void bravo(const cd& disk);
int main()
{
  cd c1("b\0", "c\0", 14, 35.5);
  classic c2 = classic("p\0", "c\0", "a\0", "p\0", 2, 57.17);
  cd* pcd = &c1;
  c1.report();
  c2.report();
  pcd->report();
  pcd = &c2;
  pcd->report();
  bravo(c1);
  bravo(c2);
  classic copy;
  copy = c2;
  //copy.report();
  return 0;
}
void bravo(const cd& disk) {
  disk.report();
}

classic.h:
#ifndef classic
#include "cd.h"
class classic :public cd {
private:
  char cursong[20];
  char curperform[50];
  //char* cursong;
public:
  classic(const char* s1, const char* s2,const char *s3, const char * s4,int n, double x);
  virtual void report()const;
  classic();
  classic& operator=(const classic& d);
};
#endif // !classic

classic.cpp:
#define _CRT_SECURE_NO_WARNINGS
#include "classic.h"
#include <string.h>
#include <iostream>
using std::cout;
classic::classic(const char* s1, const char* s2, const char* s3, const char* s4, int n, double x):cd(s1,s2,n,x) {
  strcpy(curperform, s4);
  strcpy(cursong, s3);
}
void classic::report() const{
  cd::report();
  for (auto& x : cursong) {
    if (x == '\0') break; cout << x;
  }
  cout << "\n";
  for (auto& x : curperform) {
    if (x == '\0') break;
    cout << x;
  }
  cout << "\n";
}
classic& classic::operator=(const classic& d) {
  if (this == &d) return *this;
  strcpy(cursong, d.cursong);
  strcpy(curperform, d.curperform);
  cd::operator=(d);
  return *this;
}

Help me please. (if you need files cd.cpp and cd.h write).
Errors in vs:

Error LNK2019 unresolved external symbol reference "public: __thiscall cd::cd(void)" ([email protected]@[email protected])

and

Error LNK1120 unresolved externals: 1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2021-07-01
@rybic


Ошибка LNK2019 ссылка на неразрешенный внешний символ "public: __thiscall cd::cd(void)" ([email protected]@[email protected])

says that the implementation of the constructor of the cd class without parameters was not found.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question