Constructor initializer list

https://www.youtube.com/watch?v=1nfuYMXjZsA          from this url  

let's demonstrate something that really matters 

 
 
	class Entity
{
public:

	Entity() 
	{
		std::cout << "wtf" << std::endl;
	}
	Entity(int x)
	{
		std::cout << x << std::endl;
	}
};

	class SecondEntity
	{
	private:
		int x;
		std::string str;
		Entity sb;
	public:
		SecondEntity()
			{
			x = 1;
			sb = Entity(12312);// over here  we got a problem  that 's  without the initializer list we could construct the sb twice .the first time is in the Entity one ;the second time is in the blanket
		}
	};


猜你喜欢

转载自blog.csdn.net/fly1ng_duck/article/details/80052966