Welcome to stackoverflow and C++!
I tool the liberty of fixing some smaller issues with the code:
<cmath>
is the proper C++ header, use that instead of <math.h>
(the C header. C and C++ are different).
Do not build an early habit of using namespace std
. Yes, it seems convenient, but read here why you should not do it.
Using std::endl
will likely drop your performance. Read here about the differences. using \n
works just as good, is cross-platform-compatible and even less to type.
Does this achieve what you want?
#include <cmath>
#include <iostream>
#include <string>
class People{
public:
std::string name;
int age;
bool educated;
People(){
std::cout << typeid(*this).name() << "class people is initialised\n";
}
~People(){
std::cout << typeid(*this).name() << "class people is destroyed\n";
}
private:
double worth;
};
int main(){
People Joe;
}
Responding to the comment:
People(std::string const& str)
: name(str)
{
std::cout << name << " class people is initialised\n";
}
////
int main(){
Person Joe("Joe");
}
Note this important difference:
People(std::string str)
will create a copy of the string (which is usually expensive).
People(std::string const& str)
will create a constant reference. Constant means it can not be changed and since it is a reference, it will not be copied here (it will be copied into the class member though).