我正在编写代码,我知道我有一个例外,但我确信我的程序不会属于该例外,但 Visual Studio 不让我编译我的代码,这是一种解决方法吗?
我试过 try catch 但它不起作用,我不确定如何使用 noexecpt 和 ether 它是否可以在这里使用。
void func(auto value, bool loc)
{
bool chk == loc;
if(chk == 1)
{
int ans = value;
}
else
{
string ret = value;
}
}
我想选择值的位置取决于它的类型 for -> chk = 1 它是一个 int for -> chk = 2 它是一个字符串
老实说,我没有看到您尝试去的重点,我怀疑您只需要函数重载:
void func(int value)
{
// Some code working with int
}
void func(string value)
{
// Some code working with string
}
void f()
{
func(42); // calls the first variant
func(string{}); // calls the second variant
}
不需要传递额外的参数来表明类型是什么
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句