我试图在我的程序中使用一个简单的ScrollViewer,但我遇到了问题.
如果我将所有内容都包含在ScrollViewer中的程序中,它可以正常工作:
<Window x:Class="WpfTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Name="PrimaryWindow">
<ScrollViewer>
<StackPanel>
<Menu Height="21" VerticalAlignment="Top">
<MenuItem Header="File"/>
<MenuItem Header="Edit"/>
</Menu>
<StackPanel>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="3"/>
<TextBlock Text="4"/>
<TextBlock Text="5"/>
<TextBlock Text="6"/>
<TextBlock Text="7"/>
<TextBlock Text="8"/>
<TextBlock Text="9"/>
<TextBlock Text="10"/>
</StackPanel>
</StackPanel>
</ScrollViewer>
</Window>
Run Code Online (Sandbox Code Playgroud)
但是,由于菜单是ScrollViewer的一部分,当用户向下滚动时,菜单会滚动屏幕.所以我只将ScrollViewer放在菜单下的控件周围:
<Window x:Class="WpfTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Name="PrimaryWindow">
<StackPanel>
<Menu Height="21" VerticalAlignment="Top">
<MenuItem Header="File"/>
<MenuItem Header="Edit"/>
</Menu>
<ScrollViewer>
<StackPanel>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="3"/>
<TextBlock Text="4"/>
<TextBlock Text="5"/>
<TextBlock Text="6"/>
<TextBlock Text="7"/>
<TextBlock Text="8"/>
<TextBlock Text="9"/>
<TextBlock …Run Code Online (Sandbox Code Playgroud) typedef decltype(true ? (long&&)0 : (long&&)0) T;
Run Code Online (Sandbox Code Playgroud)
应该是什么?
根据gcc(4.7),它是long.根据clang(trunk),它是long&&.这种差异导致clang无法编译使用gcc 4.7的libstdc ++的代码.谁是对的?
更新:正如ildjarn指出的那样,Clang是对的,正如Richard Smith指出的那样,错误libstdc ++是由于标准中的错误引起的.以下是相关的GCC错误以及相关的缺陷报告.
例如,GCC和clang都无法编译以下代码:
struct S {};
namespace N
{
void g(S);
}
using N::g;
namespace N
{
void g(int);
}
int main()
{
g(0);
}
Run Code Online (Sandbox Code Playgroud)
有错误:
test.cpp: In function 'int main()':
test.cpp:17:8: error: could not convert '0' from 'int' to 'S'
g(0);
^
Run Code Online (Sandbox Code Playgroud)
建议using声明仅导入在using声明出现点之上声明的重载,而不是稍后出现的(但在使用名称之前).
这种行为是否正确?
我今天遇到了一个奇怪的情况,声明一个带有某些参数的已删除运算符改变了看似无关的代码的行为.
我将它减少到以下.从这开始:
namespace N
{
enum E { A, B };
struct C
{
C(E);
private:
C(int);
};
}
N::E operator|(N::E, N::E);
namespace N
{
void Waldo()
{
C(A | B);
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,C有两个构造函数,一个是公共的,另一个是私有的.此代码编译,表明正在选择公共重载,因此表达式A | B具有类型E.反过来,这也意味着,operator|(N::E, N::E)已被匹配(否则A和B将接受隐式转换为整数的类型,A | B会int和私人构造函数相匹配.
到现在为止还挺好.现在我定义一个新的枚举类型F,并删除operator|涉及F:
namespace N
{
enum E { A, B };
struct C
{
C(E);
private:
C(int);
};
}
N::E operator|(N::E, N::E);
namespace N …Run Code Online (Sandbox Code Playgroud) 我在bash中遇到以下行为,我觉得很烦人:
export VARIABLE=~/<tab>.VARIABLE=,只留下export ~/.为什么会这样?
我的bash版本是4.3.33,OS是Debian测试,终端是Konsole.
Sutter和Alexandrescu的编码标准告诉我们通过引用捕获异常.
当然,像这样的一揽子建议通常会偶尔有例外(没有双关语意).是否有任何使用案例,首选按值列出异常?
以下代码是否有效?
struct A
{
struct nested;
};
struct B : public A {};
struct B::nested {};
Run Code Online (Sandbox Code Playgroud)
gcc接受它,但是clang拒绝它并出现以下错误:
test.cpp:8:14: error: no struct named 'nested' in 'B'
class B::nested {};
~~~^
Run Code Online (Sandbox Code Playgroud) 我遇到过一个用例,std::mem_fn它不能做手工包装函数可以做的事情.当包装函数用于不属于方法类的东西,但是可以隐式转换为它的类型时,它会出现:
#include <functional>
struct A
{
};
struct B
{
B(A); // implicit conversion from A to B
void foo() const;
};
auto foo1 = std::mem_fn(&B::foo); // std::mem_fn
void foo2(const B& b) { b.foo(); } // hand-rolled wrapper
int main()
{
A a;
foo1(a); // doesn't work
foo2(a); // works fine
}
Run Code Online (Sandbox Code Playgroud)
调用foo1的编译器错误如下(使用GCC 4.8):
In file included from test.cpp:1:0:
functional: In instantiation of '_Res std::_Mem_fn<_Res (_Class::*)(_ArgTypes ...)const>::_M_call(_Tp&, const volatile void*, _ArgTypes ...) const [with _Tp = A; _Res …Run Code Online (Sandbox Code Playgroud) 第一
我有一个包含绘图功能的类Node.节点包含在地图中,例如:
map<std::string, Node*>
Run Code Online (Sandbox Code Playgroud)
当我使用迭代器绘制地图中的所有节点时,没有任何反应.(gc是我传递给绘图函数的图形上下文)
std::map<std::string, Node*>::const_iterator itr = _Nodes.begin();
while(itr != _Nodes.end())
{
itr->second->setX(100);
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用.但是,如果我构造我的迭代器不同,它的工作原理.
std::map<std::string, Node*>::const_iterator end = _Nodes.end();
for(std::map<std::string, Node*>::const_iterator it = _Nodes.begin(); it != end; ++it){
it->second->draw(gc);
it->second->setSize(100);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么一个工作而不是另一个?
第二个问题是什么是存储NodeManager类中的所有节点而不必命名它们的替代方法?只是一个简单的清单?
c++ ×7
c++11 ×3
clang ×2
gcc ×2
namespaces ×2
bash ×1
c# ×1
decltype ×1
enums ×1
inheritance ×1
iterator ×1
map ×1
mem-fun ×1
nested-class ×1
overloading ×1
scope ×1
scrollviewer ×1
wpf ×1