If I inherit some attributes from my father's pure virtual class and want to implement them in main, do I have to redefine them in the inherited class?
This is pure virtual class Father with attributes m_name and m_preperties.
There is inherited class Son. Son has his own attribute m_school and also Father's m_name and m_properties.
I would like to implement all three values in main.
I know how to implement son's attribute school, but do I implement Father's attributes right? I ask because I define it same like non-inherited attributes and it looks strange for me.
Thank you
UPDATE: I made Father's attributes defined in Son.h as comment. But not i still don't work. This is error message:
"C:\Program Files\JetBrains\CLion 2023.1\bin\cmake\win\x64\bin\cmake.exe" --build C:\Users\mirek\CLionProjects\family\cmake-build-debug --target family -j 6
[1/3] Building CXX object CMakeFiles/family.dir/main.cpp.obj
[2/3] Building CXX object CMakeFiles/family.dir/Son.cpp.obj
[3/3] Linking CXX executable family.exe
FAILED: family.exe
cmd.exe /C "cd . && C:\PROGRA~1\JETBRA~1\CLION2~1.1\bin\mingw\bin\G__~1.EXE -g CMakeFiles/family.dir/main.cpp.obj CMakeFiles/family.dir/Father.cpp.obj CMakeFiles/family.dir/Son.cpp.obj -o family.exe -Wl,--out-implib,libfamily.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:\Program Files\JetBrains\CLion 2023.1\bin\mingw\bin/ld.exe: CMakeFiles/family.dir/Son.cpp.obj:Son.cpp:(.rdata$.refptr._ZTV3Son[.refptr._ZTV3Son]+0x0): undefined reference to `vtable for Son'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Father.h
#include <iostream>
#include <string>
#include <vector>
#include "Father.h"
class Father {
protected:
std::string m_name;
std::vector<std::string> m_properties;
public:
virtual int calculateSalary() = 0;
};
Father.cpp
#include "Father.h"
Son.h
#include <iostream>
#include "Father.h"
class Son: public Father{
std::string m_school;
//std::string m_name; //is it right?
//std::vector<std::string> m_properties; //is it right?
public:
Son(std::string school, std::string name, std::vector<std::string> properties);
int calculateSalary();
};
Son.cpp
#include "Son.h"
Son::Son(std::string school, std::string name, std::vector<std::string> properties){
m_school = school;
m_name = name;
m_properties = properties;
}
main.cpp
int main() {
Son* son1 = new Son("Harward", "Mirek", {"asd","yxc"}); //Son's school attribute and Father's attribute name and properties vector
}