我在将新Drawable设置为ProgressBar时遇到问题.
如果我在onCreate()方法中使用setProgressDrawable()它可以很好地工作.但是当我尝试在Handler post回调中调用相同的方法时,它不起作用,并且进度条消失了.
有人可以解释这种行为吗?我怎么解决这个问题?
这个问题有这段代码:
A::A(const char *pc) {
A(string(pc));
}
A::A(string s) {
vector<string> tmpVector;
tmpVector.push_back(s);
A(tmpVector); // <-- error
}
// Constructor
A::A(vector<string> filePathVector) {
}
Run Code Online (Sandbox Code Playgroud)
问题是A(tmpVector);
与vector<string> tmpVector;
以下冲突:
error: conflicting declaration 'A tmpVector'
error: 'tmpVector' has a previous declaration as 'std::vector<std::basic_string<char> > tmpVector'
Run Code Online (Sandbox Code Playgroud)
答案是:
这个
A(tmpVector);
与此相同
一个tmpVector; //但是已经存在一个名为tmpVector的对象
添加评论:
在这种情况下,()是多余的.
我的问题是:为什么括号多余?究竟在C++ 11规范中究竟是什么呢?我以前没见过这个.
情况
我正在研究Nick Hodges的"更多编码在Delphi中",他正在使用TFraction
记录来解释运算符重载.我自己写了这样的记录:
type
TFraction = record
strict private
aNumerator: integer;
aDenominator: integer;
function GCD(a, b: integer): integer;
public
constructor Create(aNumerator: integer; aDenominator: integer);
procedure Reduce;
class operator Add(fraction1, fraction2: TFraction): TFraction;
class operator Subtract(fraction1, fraction2: TFraction): TFraction;
//... implicit, explicit, multiply...
property Numerator: integer read aNumerator;
property Denominator: integer read aDenominator;
end;
Run Code Online (Sandbox Code Playgroud)
当然,我必须创建一个构造函数,因为在Q(有理数)中我必须有一个不等于零的分母.
constructor TFraction.Create(aNumerator, aDenominator: integer);
begin
if (aDenominator = 0) then
begin
raise Exception.Create('Denominator cannot be zero in rationals!');
end;
if ( (aNumerator < 0) …
Run Code Online (Sandbox Code Playgroud) 是否有标准库的实用程序,以获得指标给定的类型的std::variant
?或者我应该为自己制作一个?也就是说,我想获得B
in 的索引std::variant<A, B, C>
并获得该返回1
.
有std::variant_alternative
相反的操作.当然,std::variant
列表上可能有很多相同的类型,所以这个操作不是双射,但对我来说这不是问题(我可以首先出现列表中的类型,或列表上的唯一类型std::variant
).
请参阅以下步骤以重现.适用于XE2,但不适用于XE8.
TButton
和一个TOpenDialog
OnClick
事件调用中OpenDialog1.Execute
使用XE8订阅更新1(Windows从8.1升级到10)进行测试
我有一个函数,它接受特定模板类型的参数; 简化版可能如下所示:
#include <type_traits>
template <typename T>
struct foo
{
// default constructor
foo() { }
// simple copy constructor that can construct a foo<T> from a foo<T>
// or foo<const T>
foo(const foo<typename std::remove_const<T>::type> &) { }
};
Run Code Online (Sandbox Code Playgroud)
在功能上,foo
行为类似于a shared_ptr<T>
,具有与此问题无关的一些其他插件功能.该函数的语义规定它更喜欢接受a foo<const T>
.foo<const T>
是隐式可构造的foo<T>
,所以我希望能够做如下的事情:
template <typename T>
void bar(foo<const T> f) { }
int main()
{
bar(foo<const int>()); // fine
bar(foo<int>()); // compile error
}
Run Code Online (Sandbox Code Playgroud)
这失败了,因为没有匹配的重载,bar
因为a foo<int>
(即使a foo<const int> …
我找不到AtomicCmpExchange
(似乎隐藏)的实现,所以我不知道它的作用.
是AtomicCmpExchange
在所有平台上可靠吗?它是如何在内部实施的?它是否使用类似临界区的东西?
我有这种情况:
MainThread:
Target := 1;
Run Code Online (Sandbox Code Playgroud)
线程1:
x := AtomicCmpExchange(Target, 0, 0);
Run Code Online (Sandbox Code Playgroud)
线程2:
Target := 2;
Run Code Online (Sandbox Code Playgroud)
Thread3:
Target := 3;
Run Code Online (Sandbox Code Playgroud)
将x
永远是一个整数1,2或3,或可能是别的东西吗?我的意思是,即使AtomicCmpExchange(Target, 0, 0)
未能交换该值,它是否返回一个"有效"整数(我的意思是,不是半读取整数,例如,如果另一个线程已经开始写入该值的一半)?
我想避免使用临界区,我需要最大速度.
从1年开始,我们就开始在Delphi7中使用VirtualTreeView v5.5.3,非常喜欢!
我们想充分利用该组件的潜力,但是BeginSynch
帮助文件中只有很少的关于该方法的信息。
什么时候应该BeginSynch + EndSynch
使用BeginUpdate + EndUpdate
?
哪一个应嵌套在另一个中?
在这种情况下可以使用哪些方法?(Sort
,ScrollIntoView
,MoveTo
,NodeHeight
,isVisible[]
,...),以组画的操作,以加快应用程序之前?
当字符串位于容器中时,我在将字符串作为 lambda 的引用传递时遇到问题。我猜当我调用该函数时它会消失(超出范围)init()
,但为什么呢?然后,当我将它作为字符串引用传递时,为什么它不会消失?
#include <iostream>
#include <string>
struct Foo {
void init(int num, const std::string& txt)
{
this->num = num;
this->txt = txt;
}
int num;
std::string txt;
};
int main()
{
auto codegen1 = [](std::pair<int, const std::string&> package) -> Foo* {
auto foo = new Foo;
foo->init(package.first, package.second); //here string goes out of scope, exception
return foo;
};
auto codegen2 = [](int num, const std::string& txt) -> Foo* {
auto foo = new Foo;
foo->init(num, txt);
return …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将旧的 C++03 代码库迁移到 C++11。但我无法理解 gcc 在以下情况下警告我的内容:
\n% g++ -std=c++03 t.cxx\n% g++ -std=c++11 t.cxx\nt.cxx: In function \xe2\x80\x98int main()\xe2\x80\x99:\nt.cxx:8:21: warning: converting to \xe2\x80\x98A\xe2\x80\x99 from initializer list would use explicit constructor \xe2\x80\x98A::A(int)\xe2\x80\x99\n 8 | int main() { B b = {}; }\n | ^\nt.cxx:8:21: note: in C++11 and above a default constructor can be explicit\n
Run Code Online (Sandbox Code Playgroud)\nstruct A {\n explicit A(int i = 42) {}\n};\nstruct B {\n A a;\n};\n \nint main() {\n B b = {};\n return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n我在这里想做的只是基本的零初始化。这对于 C++03 似乎是合法的,但我无法理解如何在 …
c++ ×5
delphi ×4
c++11 ×3
android ×1
c++17 ×1
constructor ×1
delphi-xe8 ×1
gcc-warning ×1
progress-bar ×1
records ×1
reference ×1
topendialog ×1
vcl-styles ×1
windows-10 ×1