我需要消除gcc -Wconversion警告.例如
typedef unsigned short uint16_t;
uint16_t a = 1;
uint16_t b = 2;
b += a;
Run Code Online (Sandbox Code Playgroud)
给
warning: conversion to 'uint16_t {aka short unsigned int}' from 'int' may alter its value [-Wconversion]
b += a;
~~^~~~
Run Code Online (Sandbox Code Playgroud)
我可以消除这一点
uint16_t a = 1;
uint16_t b = 2;
b = static_cast<uint16_t>(b + a);
Run Code Online (Sandbox Code Playgroud)
有没有办法保持operator+=并消除警告?谢谢.
编辑
我用
gcc test.cpp -Wconversion
我的gcc版本是
gcc.exe(Rev3,由MSYS2项目构建)7.2.0
在某些机器上但在其他机器上没有我System.ObjectDisposedException使用这个类.
class LogComparer
{
private string firstFile;
private string secondFile;
private IEnumerable<string> inFirstNotInSecond;
private IEnumerable<string> inSecondNotInFirst;
public LogComparer(string firstFile, string secondFile)
{
if (!File.Exists(firstFile) || !File.Exists(secondFile))
{
throw new ArgumentException("Input file location is not valid.");
}
this.firstFile = firstFile;
this.secondFile = secondFile;
GenerateDiff();
}
public string FirstFile
{
get
{
return firstFile;
}
}
public bool IsEqual
{
get
{
return inFirstNotInSecond.SequenceEqual(inSecondNotInFirst);
}
}
public string SecondFile
{
get
{
return secondFile;
}
}
public IEnumerable<string> InFirstNotInSecond
{ …Run Code Online (Sandbox Code Playgroud) 有人可以帮我解释为什么输出是2而不是3?谢谢.
int main()
{
std::shared_ptr<int> x(new int);
std::shared_ptr<int> const& y = x;
std::shared_ptr<int> z = y;
std::cout << x.use_count() << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)