A non-const char* should not point to a string literal. This will give a warning in C++03, and will not compile in C++11 and beyond.
Change char* to const char* in your Sales constructor. The char* name in your class can stay the same. You also never copy over the actual characters in the string you allocate space for on line 18 (Hint: strcpy).
PS: Variable names like 'a' are usually not good, because they tell me nothing about what the variable means.
Visual Studio's Intellisense (the squiggly red line under 1300) is "misreporting" the int as being the problem. As Ganado points out the problem is your use of the string literal ("John") being passed to the ctor.
Two errors, one problem:
Error E0310 default argument of type "const char *" is incompatible with parameter of type "char *"
Error E0289 no instance of constructor "Sales::Sales" matches the argument list
#include <iostream>
#include <cstring>
class Sales
{
public:
Sales(double = 0.0, constchar* = "Nobody");
~Sales();
void print();
private:
double totalSales;
char* name;
};
int main()
{
Sales john(1300, "John");
john.print();
}
Sales::Sales(double a, constchar* n)
{
totalSales = a;
name = newchar[strlen(n) + 1];
// gotta copy the const c-str to your data member c-str
strcpy_s(name, strlen(n) + 1, n);
}
Sales::~Sales()
{
delete[] name;
}
void Sales::print()
{
std::cout << "Name: " << name << "\nTotal Sales: " << totalSales << '\n';
}
Why strcpy_s instead of strcpy? VS gets a bit anal about buffer overflows. The strcpy_s string function used to be one only provided by VC++, but with C11 is now part of the standard. https://en.cppreference.com/w/c/string/byte/strcpy
And yes, VS 2019 apparently defaults to the C11 standard.