C++ Overload Static Function with Non-Static Function
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I would like to print two different things depending on whether a function is called statically with Foo::print() or from an instance of Foo foo; foo.print(); EDIT: Here is a class definition that definitely does not work, as answered by a few people already. class Foo { string bla ; Foo () { bla = "nonstatic" ; } void print () { cout << bla << endl ; } static void print () { cout << "static" << endl ; } }; However, is there a good way of achieving this effect? Basically, I would like to do: if ( this is a static call ) do one