Another way of for this?

I'm having this code.

int GetFoo(const std::string& name) const;


int CLASS::Foo(int x)
{
    char Name[1024];
    snprintf(Name, sizeof(Name), "string_%d", x);
    return GetFoo(Name);
}

Is there another smarter way to write/improve this function ? using c++

1 answer

  • answered 2019-10-22 08:30 churill

    Depends on what you mean with "improve", but since the question is tagged c++ I suggest to use actual c++:

    int CLASS::Foo(int x)
    {
        return GetFoo("string_" + std::to_string(x));
    }