这在Visual C++ 2015 Update 3 RC上编译并运行良好:
class A
{
template <class T> void f() {}
};
class B : A {};
class C : A {};
class D : B, C {};
int main()
{
D d;
d.f<int>();
}
Run Code Online (Sandbox Code Playgroud)
这段代码有两个问题:
f()是私有的,所以d.f<int>()应该编译失败.f()是模棱两可的,因为它可能是B::f()或C::f().但是,没有诊断,/Wall并且B::f()被称为.颠倒顺序D继承自get C::f()调用,所以我猜它只是使用列表中的第一个基类.
g ++和clang都是正确的.我错过了什么,或者这是Visual C++中的错误?
我最近查看了我的旧代码,我无法弄清楚这是做什么的,或者它是否有效.代码类似于:
map<string, string> map;
map[string1] = ("s", string2);
Run Code Online (Sandbox Code Playgroud) 我已经读过需要比较函数需要qsort()有3个结果:
val1 < val20 如果 val1 == val2val1 > val2据我所知,排序数组只需要一个返回true或false的谓词.以冒泡为例:
int compare(int a, int b)
{
if(a>b) return 1;
return 0;
}
void bubbleSort(int arr[], int n)
{
int i, j;
for (i = 0; i < n-1; i++)
for (j = 0; j < n-i-1; j++)
if ( compare(arr[j],arr[j+1]) )
swap(&arr[j], &arr[j+1]);
}
Run Code Online (Sandbox Code Playgroud)
那么为什么qsort()比较函数需要有3种可能的结果而不是2呢?
vector我有一个带有成员变量的类T,该变量已声明但未定义。如果没有定义该类的析构函数,这可能会出现问题,因为编译器可能会选择其他一些翻译单元来生成析构函数。如果该 TU 没有 的定义,则T编译会失败。
struct undefined;
struct S
{
S(int);
std::vector<undefined> v;
};
int main()
{
S s(42); // fails in ~vector(), `undefined` is undefined
}
Run Code Online (Sandbox Code Playgroud)
为了解决这个问题,我通常在实现该类的文件中添加一个默认的析构函数作为锚点,该类可以访问该定义。
struct undefined;
struct S
{
S(int);
~S(); // implemented in another TU as `S::~S() = default;`
std::vector<undefined> v;
};
int main()
{
S s(42); // ok
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试对继承基类构造函数的派生类执行相同的操作:
#include <vector>
struct undefined;
struct base
{
base(int);
};
struct derived : base
{
using base::base;
~derived();
std::vector<undefined> v;
}; …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
class A {
private:
int i;
};
class B : public A {
private:
int j;
};
Run Code Online (Sandbox Code Playgroud)
当我检查时sizeof(B),似乎是sizeof(base) + sizeof(derived).但是,我对继承的理解是private基类的成员不会被继承.那为什么他们被包括在结果中sizeof(B)呢?
以下内容在 Visual C++ 2015 Update 2 上运行良好。请注意,它A是不可复制的,并且A::A是explicit.
#include <iostream>\n#include <tuple>\n\nstruct A\n{\n explicit A(int i)\n {\n std::cout << i << " ";\n }\n\n // non-copyable\n A(const A&) = delete;\n A& operator=(const A&) = delete;\n};\n\n\ntemplate <class... Ts>\nstruct B\n{\n std::tuple<Ts...> ts;\n\n B(int i)\n : ts((sizeof(Ts), i)...)\n {\n }\n};\n\n\nint main()\n{\n B<A, A, A, A> b(42);\n}\nRun Code Online (Sandbox Code Playgroud)\n\n目标是将相同的参数传递给所有元组元素。它正确输出:
\n\n42 42 42 42\nRun Code Online (Sandbox Code Playgroud)\n\n但是,它无法在 g++ 4.9.2 上编译。在众多消息中,tuple我认为应该调用构造函数重载:
In instantiation of \xe2\x80\x98B<Ts>::B(int) [with Ts = …Run Code Online (Sandbox Code Playgroud) 我想使用CEF来控制Flash Applikation,因此我需要一个模拟MouseDown和KeySend Execute而不需要Javascript.我搜索得非常多,但我没有找到剪辑.只是一些尝试(屏幕外):
managedCefBrowserAdapter.OnMouseButton(
500, 500, 0, true, 2, CefEventFlags.LeftMouseButton);
Run Code Online (Sandbox Code Playgroud)
要么
MouseEvent a = new MouseEvent();
a.Modifiers = CefEventFlags.LeftMouseButton;
a.X = 500;
a.Y = 500;
Run Code Online (Sandbox Code Playgroud)
要么
managedCefBrowserAdapter.SendKeyEvent(0, 0, 0);
Run Code Online (Sandbox Code Playgroud)
没有什么对我有用:(,谢谢你的帮助:)
std::this_thread::sleep_until(
std::chrono::time_point<std::chrono::system_clock>::max());
Run Code Online (Sandbox Code Playgroud)
和这个:
std::this_thread::sleep_for(
std::chrono::system_clock::durat??ion::max());
Run Code Online (Sandbox Code Playgroud)
在 Visual C++ 2017 RC 上运行此代码实际上根本不休眠。我没有检查过这个sleep_until()案例,所以我不确定那里发生了什么。
在这种sleep_for()情况下,通过将给定duration的时间添加到绝对时间,system_clock::now()然后将其转发到sleep_until(). 问题是加法溢出,给一个时间过去。
查看 30.3.2 中的 C++17 草案,既没有sleep_until()也sleep_for()没有提到限制。时序规范(30.2.4) 中没有任何相关内容。至于duration::max(),它在duration_values(20.17.4.3)中描述为:“返回的值应比较大于zero()”,这根本没有帮助。
老实说,我很惊讶地看到sleep_for()失败system_clock::duration::max(),因为它是一个对我来说非常有意义的构造。
我可以传递给那些具有明确定义行为的函数的最高值是多少?
c++ ×6
inheritance ×2
.net ×1
algorithm ×1
ambiguous ×1
c ×1
c# ×1
c++-chrono ×1
cefsharp ×1
constructor ×1
destructor ×1
dictionary ×1
explicit ×1
private ×1
sleep ×1
sorting ×1
tuples ×1
visual-c++ ×1