Function Hiding


If there is a functions in base class and one in subclass that has the same name,
the one in subclass always hides the one in base class, regardless of the parameter list and virtual function or not.
Access base class function through sub class object with a different parameter is a compiling error.
Consider this code snippet:

struct CBase
{
	void funcNonVirtual(int i)
	{
		printf("CBase::funcNonVirtual\n");
	}
};
struct CSub: CBase
{
	void funcNonVirtual(char * string)
	{
		printf("CSub::funcNonVirtual\n");
	}
};
void TestHide()
{
	CSub Sub;
	Sub.funcNonVirtual(2); //comiling error
}
Advertisements

Variadic templates


A function can take any number any type of arguments in in cpp11

template <class T>
void VariadicPrint(T tail)
{
	cout << tail << endl;
}

template <class T, class ...Args>
void VariadicPrint(T head, Args... rest)
{
	cout << head << " ";
	VariadicPrint(rest...);
}

void TestVariadic()
{
	VariadicPrint(1, "a"); //output: 1 a
}

VariadicPrint(1, “a”) outputs “1 a”

Switch network between Home and Public


Public network is more secure, but private network if more convenient.
To switch between the two on Windows 10:
Left click the wireless icon on task bar, then Properties.
It shows two radio buttons to indicate the connection: Public and Private.

I could not find it before because I thought it’s a property of the adapters, and kept looking under “Change adapter settings” in “Network and Sharing Center” in Control Panel. That was a mistake.

Ternary conditional operator is not shortcut of if-else


Reference can be initialized by ?:, but cannot by if-else.
The same is true for const initialization and initialization list on constructors.
Consider this code snippet:

	int a = 0, b = 1, bCondition = false;
	int & c = bCondition ? a : b;
	c = 2;
	_ASSERT(b == 2);
	(bCondition ? a : b) = 3;
	_ASSERT(b == 3);

The root distinction is that ?: is expression but if-else is statement.