I started learning C++ on a book a while ago and now I'm stuck with a part of code from the book that doesn't work on my API, which is Visual Studio 2019. The book is from 2000, so this might be part of the problem, but if it is could you tell my how to patch it?
The problem is in the following code. The author of the book wants to use a char array as an argument for the constructor and does it with a pointer (char* pName). However, Visual Studio underlines the argument ("0. DannyBoy"). I looked around for answers, but none look like mine. It would be much appreciated if someone could help me!
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
const int MAXNAMESIZE = 40;
class Student
{
public:
Student(char* pName)
{
strncpy_s(name, pName, MAXNAMESIZE);
name[MAXNAMESIZE - 1] = '\0';
semesterHours = 0;
gpa = 0;
}
//... autres membres publics...
protected:
char name[MAXNAMESIZE];
int semesterHours;
float gpa;
};
int main(int argcs, char* pArgs[])
{
Student s("0. DannyBoy");
Student* pS = new Student("E. Z. Rider");
system("pause");
return 0;
}