I get
error: could not convert 'p1' from 'Person (*)()' to 'Person'
whenever i use the default constructor (when i create Person p1), i know it's because i'm using a char array but i have to use it, i can't use strings
i'm also getting 2 warnings
warning: converting to non-pointer type 'char' from NULL [-Wconversion-null]|
in the default constructor
warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
when i create Person p2
so here's my code
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
class Person{
private:
char* name;
char gender;
int age;
public:
Person();
Person(char*, char, int);
friend void printInfo(Person);
};
Person::Person()
:name(NULL), gender(NULL), age(0) // this results in the first warning
{
}
Person::Person(char* n, char g, int a)
:name(n), gender(g), age(a)
{
}
void printInfo(Person p){
cout << "Name: " << p.name << endl;
cout << "Age: " << p.age << endl;
cout << "Gender: " << p.gender << endl;
}
int main()
{
Person p1(); // this results in an error
printInfo(p1);
Person p2("Max", 'm', 18); // this results in the second warning
printInfo(p2);
return 0;
}