小编Ayx*_*xan的帖子

std :: declval <T>()`没有匹配功能是什么原因?

我很惊讶地发现,对于某些人T,这decltype(std::declval<T>())是不合法的:

#include <utility>

template<typename T>
using Alias = decltype(std::declval<T>());

// as expected
using A1 = Alias<int>;
using A2 = Alias<int(int)>;

// error: no matching function for call to 'declval<...>()'
using A3 = Alias<int(int) const>;
using A4 = Alias<int(int) volatile>;
using A5 = Alias<int(int) &>;
using A6 = Alias<int(int) &&>;
// and all combinations of the above
Run Code Online (Sandbox Code Playgroud)

cppreference似乎并不表明该错误是预期的。

还有其他declval<T>不能使用的类型吗?规范在哪里定义这些?

c++ language-lawyer declval

3
推荐指数
1
解决办法
83
查看次数

Python 3 中 math.log2(x) 的时间复杂度是多少?

正如标题所说,我想知道math.log2(x). 我知道可以用 O(1) 复杂度用 C 编写这样的函数,但是我找不到有关在 Python 中实现此函数的任何信息。

logarithm time-complexity python-3.x

3
推荐指数
1
解决办法
1969
查看次数

如何制作跨度跨度

C++20std::span是一个非常好的编程接口。但是似乎没有一种简单的方法来获得跨度。这是我想要做的:

#include <iostream>
#include <span>
#include <string>
#include <vector>

void print(std::span<std::span<wchar_t>> matrix) {
  for (auto const& str : matrix) {
    for (auto const ch : str) {
      std::wcout << ch;
    }
    std::wcout << '\n';
  }
}

int main() {
  std::vector<std::wstring> vec = {L"Cool", L"Cool", L"Cool"};
  print(vec);
}
Run Code Online (Sandbox Code Playgroud)

这不编译。我该怎么做?

c++ c++20 std-span

3
推荐指数
1
解决办法
290
查看次数

如何从两个迭代器创建范围

刚开始使用 c++20 范围。我有一个问题是,如果你有两个迭代器到一个向量中,你如何从它们创建一个范围视图?Range 将从第一个迭代器开始,并在第二个迭代器之前结束 1。

c++ c++20

3
推荐指数
1
解决办法
109
查看次数

什么时候我应该在 C++ 中添加“类”这个词来创建指针?

在什么情况下写可能无效 Type *p = nullptr;

而只有 class Type *p = nullptr;满足?

c++ class

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

Qt - QPainter.DrawText 不绘制文本

我正在 Qt-Creator 5 中创建一个模拟时钟,现在我想将数字绘制到屏幕上,但它不起作用?

painter.drawText(QPoint(50, 50), "12");
Run Code Online (Sandbox Code Playgroud)

我绝对不明白为什么它不起作用。当我用 a 替换代码中的这一行时.drawEllipse,它工作正常。所以位置/颜色不可能是问题,除非drawText不使用setBrush()颜色。

任何人都知道如何使用 正确在屏幕上绘制文本QPainter

//previous code only draws blue ellipses with white background
QColor secondColor(240,0,0);

painter.setPen(Qt::NoPen);
painter.setBrush(secondColor);
painter.save();

QFont font=painter.font() ;
font.setPointSize(18);
painter.setFont(font);
painter.drawText(QPoint(50, 50), "12");
Run Code Online (Sandbox Code Playgroud)

因为已经到了最后paintEvent不能透支

c++ qt qpainter drawtext qt5

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

找不到C#可执行文件

我在Visual Studio 2019中创建了一个新项目并将其命名SimpleCSharpApp。编写了一个简单的HelloWorld应用程序,并在“调试模式”下进行了编译。现在,我需要可执行文件(.exe更确切地说是文件)。它应该在中SimpleCSharpApp/bin/Debug,但不存在。有一个名为的目录netcoreapp2.1,其中包含以下文件:

SimpleCSharpApp.deps.json  
SimpleCSharpApp.dll  
SimpleCSharpApp.pdb  
SimpleCSharpApp.runtimeconfig.dev.json  
SimpleCSharpApp.runtimeconfig.json  
Run Code Online (Sandbox Code Playgroud)

我如何找到可执行文件?

c# visual-studio .net-core

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

c++ - 如何重载+以求和2个矩阵对象?

我有这门课

class Matrix
{
    int size;

    std::unique_ptr<std::unique_ptr<int[]>[]>  val;

public:

    Matrix(int size1)
    {
        size=size1;
        val=std::make_unique< std::unique_ptr<int[]>[] >(size);

        ...
    }
Run Code Online (Sandbox Code Playgroud)

...移动构造函数,移动赋值运算符

    Matrix& operator+(Matrix &m)
    {
        Matrix sumMatrix(size);
        for ( int i = 0; i < size; ++i)
        {
            for (int j = 0; j < size; ++j){
                sumMatrix.val[i][j]=this->val[i][j]+m.val[i][j];
            }

        }
        return sumMatrix;
    }
Run Code Online (Sandbox Code Playgroud)

和主要:

...
Matrix e=b+c;
    std::cout<<"e="<<std::endl;
    e.print();
Run Code Online (Sandbox Code Playgroud)

我有这个错误:

警告:对局部变量“sumMatrix”的引用返回 [-Wreturn-local-addr] 矩阵 sumMatrix(size);

有人可以帮我解决这个问题吗??

c++ unique-ptr

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

当在 C++ 中需要自动删除时,这是静态的正确用法吗?

代码段是从维基百科。

void WriteToFile(const std::string& message) {
  // |mutex| is to protect access to |file| (which is shared across threads).
  static std::mutex mutex;

  // Lock |mutex| before accessing |file|.
  std::lock_guard<std::mutex> lock(mutex);

  // Try to open file.
  std::ofstream file("example.txt");
  if (!file.is_open()) {
    throw std::runtime_error("unable to open file");
  }

  // Write |message| to |file|.
  file << message << std::endl;

  // |file| will be closed first when leaving scope (regardless of exception)
  // mutex will be unlocked second (from lock destructor) when …
Run Code Online (Sandbox Code Playgroud)

c++

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

“ while” /“ for”循环的替代方案是什么

我有一门功课,我应该等到我写控制台“停止”一次又一次地做一些动作,但我不能使用forwhilegotoswitch[]typedef在我的所有代码。那么如何更换循环呢?

c++ loops

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