#include<iostream>
#include<cstring>
using namespace std;
class Employee
{
char name[5];
int id;
int age;
public:
Employee(char* a, int b, int c)
{
strcpy(name, a);
id=b;
age=c;
}
};
class Officer: public Employee
{
char officer_cadre[3];
public:
Officer(char* a, int b, int c, char* d):Employee(char* a, int b, int c)
{
strcpy(officer_cadre, d);
}
};
int main()
{
Officer o1("Nakul", 1, 2, "ABC");
return 0;
}
The above code is simple, but I'm not able to figure out why the compiler is throwing errors like 'expected primary expression before char' and 'expected primary expression before int'.
On this line
Officer(char* a, int b, int c, char* d):Employee(char* a, int b, int c)
You should just pass a,b, and c. Instead you are using the syntax to declare a,b, and c. When just referring to them you don't need the types. IE you should do:
Officer(char* a, int b, int c, char* d):Employee(a, b, c)
You may have just accidentally copy-pasted the declaration into the child class's constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With