Is there any class initialization function for C ++?
In Lua, using the classlib
library there is the __init
function, and in Python as well.
EX:
require "classlib"
Human = class();
function Human:__init(name, age)
self.name = name
self.age = age
end
gabriel = Human("Gabriel", 16)
print(gabriel.name, gabriel.age)
In C ++ I had to do this:
#include <iostream>
#include <string.h>
using namespace std;
class human {
public:
string name;
int age;
void SET(string, int);
};
void human::SET(string name, int age){
this->name = name;
this->age = age;
}
int main (){
human gabriel;
gabriel.SET("Gabriel Sales", 16);
cout << gabriel.name;
return 0;
}