我想将我的包上传到 pypi。
在最后一步中:
python setup.py sdist upload
Run Code Online (Sandbox Code Playgroud)
我遇见了:
Invalid value for blake2_256_digest. Error: Use a valid, hex-encoded, BLAKE2 message digest
Run Code Online (Sandbox Code Playgroud)
我对这个错误感到困惑,任何人都可以帮忙解决这个问题吗?
假设我有一个类,其中包含一个智能指针作为其成员变量:
class B;
class A {
public:
A(const std::shared_ptr<B>& b) : b_(b) {} // option1: passing by reference
A(std::shared_ptr<B> b) : b_(b) {} // option2: passing by value
std::shared_ptr<B> b_;
};
Run Code Online (Sandbox Code Playgroud)
我对A的构造函数有两种选择:通过智能指针构造和通过智能指针的引用构造。
这两种方法各有什么优缺点?
复制智能指针是浪费吗?
我有一个 qt c++ 普通程序。在Windows中使用mingw8.1 gcc作为编译器。
我可以在 qt Creator 中运行它。
但是当我想使用windeplotqt进行部署时,它失败了:
a.exe does not seem to be a Qt executable
Run Code Online (Sandbox Code Playgroud)
我的步骤是:
1. copy the exe from build-xxx-release/release/a.exe to a clean folder
2. open terminal from QT(mingw) from my windows start menu
3. cd the clean folder in terminal
4. windeployqt a.exe
Run Code Online (Sandbox Code Playgroud)
然后错误就出来了。
这让我发疯,因为我多次重新安装QT。我可以确保我的qt是一个干净的环境。
有人可以帮忙吗?
假设我有一个基类A和两个抽象类B和C,以及它们的派生类D和E。
如何区分DandE的最后一层类?(D的最后一层类是B,E是C)
这是代码:
#include <iostream>
using namespace std;
class ClassA { public: virtual int testFunc() { return 1; } };
class ClassB : public ClassA { public: virtual int testFunc() override =0; };
class ClassC : public ClassA { public: virtual int testFunc() override =0; };
class D : public ClassB { public: virtual int testFunc() override {return …Run Code Online (Sandbox Code Playgroud) 我想使用 std::distance 来查找元素的索引。
这是代码:
#include <iostream>
#include <map>
#include <iterator>
#include <string>
using namespace std;
int main() {
std::map<int, std::string> m = {{1, "huang"}, {2, "wei"}, {3, "pu"}};
auto it = m.find(2);
cout << std::distance(it, m.begin()) << endl; // struck here
cout << std::distance(it, m.end()) << endl;
}
Run Code Online (Sandbox Code Playgroud)
但是我发现代码被敲入了cout,我的代码有什么问题?
我可以写一个这样的类:
class Base {
template <typename...Args>
virtual double calculate(const Args&...args) = 0;
};
Run Code Online (Sandbox Code Playgroud)
然后我想这样编写派生类:
class Derived1 : public Base {
double calculate(int a) {
}
};
class Derived2 : public Base {
double calculate(int a, int c) {
}
};
Run Code Online (Sandbox Code Playgroud)
如果这是不可能的,有什么方法可以实现这一点吗?
我想为STL容器设计一个打印功能,包括:std::vector, std::map, std::unodered_map, std::set, std::unordered_set, std::list....
理想的函数如下所示:
template<typename T>
void Show(const T& t)
{
if (istype(t, std::vector))
{
// here is a presudo code
// print vector
for (auto i: t) cout << i << endl;
}
else if (istype(t, std::unordered_map))
{
// print unordered_map
}
else
{ }
}
Run Code Online (Sandbox Code Playgroud)
我认为问题发生在 istype()
我知道有一些功能std::is_same可以做到这一点。
但是好像只能操作int或者float不能操作std::vector,你能帮帮忙吗?
我有一个带有模板函数和一个特殊函数的类,如下所示:
#include <bits/stdc++.h>
using namespace std;
class A
{
public:
template <typename T>
void test(const T& t)
{
cout << "template " << t << endl;
}
void test(const std::string& s) {
cout << "test " << s << endl;
}
};
int main()
{
A a;
a.test("asdas");
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,有两个test函数:
template功能std::string。我想要的是:
test(1)-> 调用template函数test<int>(1)std::string str = "asd"; test(str);-> 调用特殊函数test(str)test("asd")-> 调用特殊函数test(std::string str = "asd")如何实现这一目标?