小编ben*_*ros的帖子

整体推广和运营商+ =

我需要消除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

c++ integer-promotion

7
推荐指数
1
解决办法
157
查看次数

IEnumerable <string> System.ObjectDisposedException

在某些机器上但在其他机器上没有我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)

c#

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

std :: shared_ptr use_count()值

有人可以帮我解释为什么输出是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)

c++ c++11

2
推荐指数
2
解决办法
95
查看次数

为什么这个if语句被评估为真?

在此输入图像描述

我只是不明白.第二个if语句被评估为true.您可以在图像中看到调试信息.如果我k在if语句中使用它,它的行为与我期望的一样.为什么是这样?谢谢.

c++

-1
推荐指数
2
解决办法
100
查看次数

标签 统计

c++ ×3

c# ×1

c++11 ×1

integer-promotion ×1