小编ale*_*exm的帖子

重载子类中的方法(Enum vs int)

为什么以下两个代码示例产生不同的输出?

情况1

enum EnumType
{
    First,
    Second,
    Third
}

class ClassB
{
    public string Func(int index)
    {
        return "Func(int)";
    }

    public string Func(EnumType type)
    {
        return "Func(EnumType)";
    }
}

class Program
{
    static void Main(string[] args)
    {
        ClassB b = new ClassB();
        Console.WriteLine(b.Func(0));
        Console.WriteLine(b.Func(EnumType.First));
        Console.ReadLine();
    }
}
Run Code Online (Sandbox Code Playgroud)

输出:

Func(int)
Func(EnumType)
Run Code Online (Sandbox Code Playgroud)

案例2

enum EnumType
{
    First,
    Second,
    Third
}

class ClassA
{
    public string Func(int index)
    {
        return "Func(int)";
    }
}

class ClassB : ClassA
{
    public string Func(EnumType enumType)
    { …
Run Code Online (Sandbox Code Playgroud)

c# overloading derived-class

6
推荐指数
1
解决办法
769
查看次数

C++ 中字符串格式化的首选方法?

这对我来说有点冗长:

ostrstream ss;
ss << "Selected elements: " << i << "," << j << ".";
string msg(ss.str(), (size_t)ss.pcount());
Run Code Online (Sandbox Code Playgroud)

是否有一种优雅的方法来使用简洁的单行语句(可能带有模板或宏)来格式化文本消息?

c++ string-formatting

5
推荐指数
1
解决办法
139
查看次数

标签 统计

c# ×1

c++ ×1

derived-class ×1

overloading ×1

string-formatting ×1