好的......我上课了
#include <functional>
template <typename TValue, typename TPred = std::less<TValue>>
class BinarySearchTree {
struct TNode {
TValue value;
TNode *pLeft;
TNode *pRight;
};
public:
BinarySearchTree();
~BinarySearchTree();
. . .
private:
TNode *pRoot;
. . .
};
Run Code Online (Sandbox Code Playgroud)
然后在我的.cpp文件中我定义了这样的ctor/dtor:
template <typename TValue, typename TPred>
BinarySearchTree<TValue, TPred>::BinarySearchTree() : pRoot(0) {}
template <typename TValue, typename TPred>
BinarySearchTree<TValue, TPred>::~BinarySearchTree() {
Flush(pRoot);
}
Run Code Online (Sandbox Code Playgroud)
我的主要功能:
int main() {
BinarySearchTree<int> obj1;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到以下链接错误:
public: __thiscall BinarySearchTree<int,struct std::less<int>>::BinarySearchTree<int,struct std::less<int> >(void)
Run Code Online (Sandbox Code Playgroud)
我试图将构造函数定义放入头文件中,我没有得到任何错误.只有当我尝试在cpp文件中定义它时.
我正在寻找一个循环进度指示Widget for Qt5,如下所示:http://anthonyterrien.com/knob/
在Qt中是否有类似的东西或可以做到这一点?
我想手动设置百分比,它不应该是一个旋转的圆圈或类似的东西
我在 Mac OSX 中设置 Qt5 组合框弹出窗口的样式时遇到一些问题
我的 QComboBox 样式表
QComboBox {
font-size: 11px;
height: 16px;
padding: 1px 5px 1px 5px;
border: 2px groove #4B4F4F;
border-bottom: 2px ridge #424545;
border-right: 2px ridge #424545;
border-radius: 3px;
color: #DEDEDE;
background: qlineargradient(x1:0, x2:0, y1:0, y2:1, stop:0 #6B6E6E, stop:1 #595B5B);
}
QComboBox::drop-down {
subcontrol-origin: padding;
subcontrol-position: top right;
width: 14px;
border-left-width: 1px;
border-left-color: #999999;
border-left-style: solid; /* just a single line */
border-top-right-radius: 3px; /* same radius as the QComboBox */
border-bottom-right-radius: 3px;
}
QComboBox::down-arrow …Run Code Online (Sandbox Code Playgroud) 在我们的环境中,我们遇到了有关库单元测试的模拟函数的问题。问题是我们想模拟单个函数而不是模拟整个模块(.c 文件)。
该库被编译为存档文件并静态链接到单元测试。没有嘲笑就没有任何问题。
现在,当尝试模拟库的单个函数时,我们显然会得到多个定义。
我现在的方法是weak在编译/链接库时使用function 属性,以便链接器在针对单元测试进行链接时采用模拟(非弱)函数。我已经对其进行了测试,它似乎按预期工作。
这样做的缺点是我们需要在代码中进行许多属性声明。
我的最后一种方法是将一些编译或链接参数传递给编译器,每个函数都自动声明为弱符号。
现在的问题是:有什么好的方法可以做到这一点吗?
btw:我们使用 clang 8 作为编译器。
可以说我在一个类中有2个Thread方法A.其中一个线程一直在运行,并且正在检查是否设置了成员变量.如果此成员变量设置为true,则应启动另一个线程.第二个线程mThread2通过检查变量来自行停止mRunThread2.
现在的问题是:是否需要对布尔变量进行互斥?写入变量需要多个汇编指令,所以在这一点上我需要同步.
class A {
public:
A() : mRunThread1(true) {
mThread1 = std::thread(&A::DoWork1(), this);
}
~A() {
mRunThread1 = false;
}
void Start2() { mRunThread2 = true; }
void Stop2() { mRunThread2 = false; }
private:
bool mRunThread1;
bool mRunThread2;
std::thread mThread1;
std::thread mThread2;
void DoWork1() {
while (mRunThread1) {
bool lastState = false;
if (mRunThread2 && !lastState) {
if (mThread2.joinable()) mThread2.join();
mThread2 = std::thread(&A::DoWork2(), this);
}
lastState = mRunThread2;
}
}
void DoWork2() …Run Code Online (Sandbox Code Playgroud) 在我的班级中A,只要对象生命周期就有一个线程运行.现在我有一个布尔成员变量,每个循环检查一次,在析构函数中,这个变量设置为false.
class A {
public:
A() : mRun(true) {
mThread = std::thread(&A::DoWork(), this);
}
~A() {
mRun = false;
}
private:
bool mRun;
std::thread mThread;
void DoWork() {
while (mRun) {
...
}
}
};
Run Code Online (Sandbox Code Playgroud)
可以while(true)安全使用吗?我读到在破坏线程时,它们将被终止.
我有以下功能:
char * strAlloc(string str) {
char * chArr = new char[str.size()];
for (size_t i = 0; i < str.size(); i++) {
chArr[i] = str[i];
}
return chArr;
}
Run Code Online (Sandbox Code Playgroud)
如果我char * chArr = new char[str.size()];在调试器说下面后休息一下:
chArr 0x00c38cf8 "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍýýýý««««««««þîþîþ"
Run Code Online (Sandbox Code Playgroud)
如果我在迭代后做了一个休息,我得到这个:
chArr 0x00c38cf8 "***************ýýýý««««««««þîþîþ"
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
编辑:
size_t const gSize = 15; typedef char *
TMaze [gSize];
Maze[0] = strAlloc ("***************");
Run Code Online (Sandbox Code Playgroud)
在类型TMaze我需要char数组的指针尝试str.size()+ 1,相同的行为
EDIT2:
char * strAlloc(string const & str) {
char * chArr = new char[str.size()+1];
strcpy(chArr, str.c_str());
return chArr; …Run Code Online (Sandbox Code Playgroud)