#include <iostream>
// a special type of method which runs every time when we instantiate an object.
// it's usually where you set variables up or do any kind of initialization that you need.
class Entity
{
public:
float X, Y;
Entity()
{
X = 0.0f;
Y = 0.0f;
}
Entity(float x, float y)
{
X = x;
Y = y;
}
void Print()
{
std::cout << X << ", " << Y << std::endl;
}
};
class Log
{
public:
Log() = delete;//tell the compiler:don't want that default constructor.
static void Write() { }
};
int main(void)
{
Entity e(10.0f, 5.0f);
e.Print();
Log::Write();
//Log l;default constructor deleted!
std::cin.get();
}
【Cherno的C++视频】Constructors in C++
于 2022-08-10 23:10:21 首次发布