I have a name of a variable in my .h file which a function has the same name…
for example:
//computer.h
class Computer{
private:
string computerName;
int cores;
}
//computer.cpp
Computer::Computer(string computerName, int cores)
{
...
}
I want to assign the values from the .cpp function to the .h file variables.
whenever i do this, it doesn’t work. Am I doing it correctly??
this.computerName = computerName;
this.cores=cores;
Instead of assignment, use initialization
Yes that works. Constructor initializer lists have that exact purpose.