如何在Visual Studio C++中允许类型转换

huangapple go评论56阅读模式
英文:

How to allow type conversions in Visual Studio C++

问题

I'm working with an old C++ application that has been certified for a certain system. So, I'm not allowed to make any changes. However, I have to make a new build in Visual Studio 2019. I am running into a lot of conversions issues like this.

void sendMsg(char* msg)
{
    // code
}

int main()
{
    sendMsg("hello");
}

[Error (active) E0167 argument of type "const char" is incompatible with parameter of type "char".]

在Visual Studio中是否有可用于允许这些类型的转换发生的设置?

英文:

I'm working with an old C++ application that has been certified for a certain system. So, I'm not allowed to make any changes. However, I have to make a new build in Visual Studio 2019. I am running into a lot of conversions issues like this.

void sendMsg(char* msg)
{
    // code
}

int main()
{
    sendMsg("hello");
}

> [Error (active) E0167 argument of type "const char" is incompatible with parameter of type "char".]

Is there a setting in Visual Studio I can use to allow these types of conversions to happen?

答案1

得分: 0

感谢,@Swift!使用/permissive就像魔法一样奏效。

我可能应该提供更多细节。
1)正如我所说,我不能改变代码的选项。
2)我必须在Visual Studio 2019中构建它。
3)原始代码是为一个更早版本的C++编写的。

我之前没有提到的要点是:
1)这是一个完整且正常运行的Linux应用程序。

a)由于应用程序已经完成,不会进行新的开发,
因此我不关心错误检查。

2)我需要在VS中构建应用程序的Windows版本。

3)代码库包含数千个文件。更改它们所有将超出我的时间预算。

4)可能有一个新版本的Linux构建。我不想引入可能导致问题的代码库,
先前是稳定的。我也不想维护两个代码库。

英文:

Thanks, @Swift! Using /permissive worked like a charm.

I probably should have given a few more details.

  1. As I said, I don't have the option of changing the code.
  2. I have to get it built in Visual Studio 2019.
  3. The original code was written for a much older version of C++

The points that I did not mention before were:

  1. This was a complete and functioning Linux application.

    a) Since the application was complete, no new development
    was going to happen. Therefore, I did not care about
    error checking.

  2. I needed to build a Windows version of the application in VS.

  3. The code base contained thousands of files. Changing all of them
    would have exceeded my time budget.

  4. There may be a new version of the Linux build. I did not want
    to introduce possible issues with a code base that was previously
    stable. I also didn't want to maintain two code bases.

huangapple
  • 本文由 发表于 2023年3月10日 01:41:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75688219.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定