I am getting an error while following along with:
I am currently at 27:02 and cannot figure out what I’ve done wrong. I’ve compiled whenever the instructor has compiled and each time it worked.
Here is my code:
#include <iostream>
using std::string;
class Employee {
public:
string Name;
string Company;
int Age;
// Here is where we have method:
void IntroduceYourself(){
std::cout << "Name - " << Name << std::endl;
std::cout << "Company - " << Company << std::endl;
std::cout << "Age - " << Age << std::endl;
}
// Constructor Method
Employee(string name, string company, int age) {
Name = name;
Company = company;
Age = age;
}
};
int main(){
// errors in this block
Employee employee1 = Employee('Saldina', 'YT-CodeBeauty', 25);
employee1.IntroduceYourself();
Employee employee1 = Employee('John', 'Amazon', 35);
employee2.IntroduceYourself();
}
Two errors follow the assignment operators in main():
When I hover over Employee I get this error:
class Employee
no instance of constructor
“Employee::Employee” matches the argument
list – argument types are: (int, int, int)C/C++(289)
And the third error is probably caused by the same problem:
When I hover over employee2, in main():
identifier “employee2” is undefined C/C++(20)
I am using Visual Studio Code on a Linux machine but I believe Constructors should work the same as on a Windows machine.