小编Rem*_*eau的帖子

如何正确使用setProgressDrawable()?

我在将新Drawable设置为ProgressBar时遇到问题.

如果我在onCreate()方法中使用setProgressDrawable()它可以很好地工作.但是当我尝试在Handler post回调中调用相同的方法时,它不起作用,并且进度条消失了.

有人可以解释这种行为吗?我怎么解决这个问题?

android progress-bar

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

怎么样'A(tmpVector);' 与'A tmpVector;'相同?

这个问题有这段代码:

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规范中究竟是什么呢?我以前没见过这个.

c++ c++11

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

Delphi是否真的需要记录构造函数?

情况

我正在研究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)

delphi constructor records

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

在std :: variant中按类型获取索引

是否有标准库的实用程序,以获得指标给定的类型std::variant?或者我应该为自己制作一个?也就是说,我想获得Bin 的索引std::variant<A, B, C>并获得该返回1.

std::variant_alternative相反的操作.当然,std::variant列表上可能有很多相同的类型,所以这个操作不是双射,但对我来说这不是问题(我可以首先出现列表中的类型,或列表上的唯一类型std::variant).

c++ c++-standard-library c++17

11
推荐指数
4
解决办法
1983
查看次数

右键单击TOpenDialog中的文件时,使用自定义样式会显示无效字符

请参阅以下步骤以重现.适用于XE2,但不适用于XE8.

  1. 创建一个新的VCL表单应用程序 - Delphi
  2. 在表格上放置一个TButton和一个TOpenDialog
  3. 在按钮OnClick事件调用中OpenDialog1.Execute
  4. 运行程序,打开文件对话框,右键单击文本文件=>显示菜单项确定
  5. 转到项目/选项/应用程序/外观.启用并选择自定义样式(例如"Ruby Graphite")并重新编译
  6. 运行程序,打开文件对话框,右键单击文本文件=>不正确显示菜单项(显示无效字符)

使用XE8订阅更新1(Windows从8.1升级到10)进行测试

delphi topendialog vcl-styles windows-10 delphi-xe8

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

是否存在允许将非const模板参数类型隐式转换为const类型的规范方法?

我有一个函数,它接受特定模板类型的参数; 简化版可能如下所示:

#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> …

c++ c++11

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

AtomicCmpExchange在所有平台上都可靠吗?

我找不到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)未能交换该值,它是否返回一个"有效"整数(我的意思是,不是半读取整数,例如,如果另一个线程已经开始写入该值的一半)?

我想避免使用临界区,我需要最大速度.

delphi

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

什么时候应该使用VirtualTree的BeginSynch vs BeginUpdate?

从1年开始,我们就开始在Delphi7中使用VirtualTreeView v5.5.3,非常喜欢!

我们想充分利用该组件的潜力,但是BeginSynch帮助文件中只有很少的关于该方法的信息。

什么时候应该BeginSynch + EndSynch使用BeginUpdate + EndUpdate

哪一个应嵌套在另一个中?

在这种情况下可以使用哪些方法?(SortScrollIntoViewMoveToNodeHeightisVisible[],...),以组画的操作,以加快应用程序之前?

delphi virtualtreeview

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

容器中的引用?

当字符串位于容器中时,我在将字符串作为 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++ reference

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

从初始化列表转换为“A”将使用显式构造函数“A::A(int)”

我正在尝试将旧的 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)\n
struct 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++ gcc-warning c++11

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