-4

I tried this code on code block and it works, but it gives me a problem in visual studio. I don't know where exactly the problem is. The error I get is:

no instance of constructor "book::book" match the argument list

Updated code:

#include<iostream>
#include<cstring>
using namespace std;
class book
{
private:
    int npage;
    char title[30];
public:
    book(char t[], int p = 33)
    {
        npage = p;
        strcpy_s(title, t);
    }
    book(book&a)
    {
        npage = a.npage;
        strcpy_s(title, a.title);
    }
    void p()
    {
        cout << "page : " << npage << endl << "title : " << title << endl;
    }
};
int main()
{
    char c[30] = "rich dad poor dad";
    book a1(c, 260);
    book a2(a1("rich dad poor dad", 260));
    a1.p();
    system("pause");
}
user4581301
  • 33,082
  • 7
  • 33
  • 54
  • 5
    You should paste your code here instead of a link to a screenshot. – SU3 Apr 14 '18 at 01:32
  • 2
    Are you sure that is an actual compiler error? I bet it isn't, but it is a message from the Intellisense tool. Compiler errors in Visual Studio have a label `C` followed by a number, not just text. – PaulMcKenzie Apr 14 '18 at 01:43
  • strcpy_s is not c++ compliant, you should use strcpy – PapaDiHatti Apr 14 '18 at 03:05

1 Answers1

0

Just to hightlight problem lies in line: book a2(a1("rich dad poor dad", 260));.

Here you are calling constructor by passing "rich dad poor dad" which is const char[18] and there you are expecting char t[], so change parameterized constructor declaration to :

book(const char t[],float p) and copy constructor to : book(const book&a)

and also a2(a1("rich dad poor dad", 260)) to book a2(a1).

PapaDiHatti
  • 1,841
  • 19
  • 26