C++语法struct A::B:A {};是什么意思?C++标准中描述的名称定义(或访问)在哪里?
#include <iostream>
struct B;
struct A {
struct B;
};
struct A::B:A {
};
int main() {
A::B::A::B b;
std::cout<<"Sizeof A::B::A::B is " << sizeof(A::B::A::B)<<std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 当我尝试访问我的解决方案属性时,我收到以下错误:
Object reference not set to an instance of an object
Run Code Online (Sandbox Code Playgroud)
我正在使用VS 2012.这可能是什么原因?


在Visual Studio 2010 64位中,我无法设计我的表单.
我一直收到这个警告(和错误):
Warning 18
The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file:
MainForm --- The base class 'Blah' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.
Run Code Online (Sandbox Code Playgroud)
这只发生在我为x64编译时......在x86中,设计师运行良好.
只是想明确我需要项目在x64上工作,因为很多项目的组件都是用x64编译的,如果表单是在x86中则无法工作.
有没有其他人遇到这个并找到了解决方案?
请考虑以下代码:
abstract class Foo<T>
where T : Foo<T>, new()
{
void Test()
{
if(Bar != null)
Bar(this);
}
public event Bar<T> Bar;
}
delegate void Bar<T>(T foo)
where T : Foo<T>, new();
Run Code Online (Sandbox Code Playgroud)
该行Bar(this)导致以下编译器错误:
参数类型Foo <T>不能分配给参数类型T.
T被约束为Foo <T>,因为我希望派生类基本上告诉基类它们的类型,以便可以在事件回调中使用该类型,以便保存实现者不必将回调参数强制转换为派生类型.
我可以看到代码不能正常工作,但我对如何正确地执行此操作有一点阻塞,而不会使用可用于任何旧事物的泛型委托.我也不太确定为什么T约束不会产生编译错误,因为它似乎是递归的.
编辑
我觉得我需要澄清一下!这是一个新的例子,我希望会更清楚.请注意,下面的OnDuckReady事件处理程序会生成编译器错误.
如何让事件以正确的类型传递?
abstract class Animal<T>
where T : Animal<T>, new()
{
void Test()
{
if(AnimalReady != null)
AnimalReady(this);
}
public event AnimalHandler<T> AnimalReady;
}
delegate void AnimalHandler<T>(Animal<T> animal)
where T : Animal<T>, new();
class Duck : Animal<Duck> …Run Code Online (Sandbox Code Playgroud) 我们正在考虑将Orchard CMS用于项目.我知道CMS已经存在很长时间了,但我想知道是否有任何已知的高调和成功案例研究使用Orchard CMS或其前身Oxite?
谢谢.
我有以下枚举定义......
namespace ItemTable
{
public enum DisplayMode
{
Tiles,
Default
}
}
namespace EffectiveItemPermissionTable
{
public enum DisplayMode
{
Tree,
FullPaths
}
}
Run Code Online (Sandbox Code Playgroud)
......然后我有以下课程......
public class Table<TDisplayMode>
where TDisplayMode: struct
{
// public
public TDisplayMode DisplayMode
{
get { return mDisplayMode; }
set { mDisplayMode = value; }
}
// private
private TDisplayMode mDisplayMode;
}
public class ItemTable : Table<ItemTable.DisplayMode>
{}
public class EffectiveItemPermissionTable : Table<EffectiveItemPermissionTable.DisplayMode>
{}
public class UISettings
{
public UISettings()
{
ItemTable = new ItemTable();
EffectiveItemPermissionTable = …Run Code Online (Sandbox Code Playgroud) 我有一个方法,使用递归遍历树并更新项目.
目前该方法处理所有项目需要很长时间,所以我开始优化.其中包括使用字典而不是为每个项目执行数据库查询.
字典定义为
System.Collections.Generic.Dictionary<EffectivePermissionKey, MyData>
Run Code Online (Sandbox Code Playgroud)
密钥类型定义为
private struct EffectivePermissionKey
{
// http://blog.martindoms.com/2011/01/03/c-tip-override-equals-on-value-types-for-better-performance/
public override bool Equals(object aObject)
{
if (aObject == null)
return false;
else
return aObject is EffectivePermissionKey && Equals((EffectivePermissionKey)aObject);
}
public bool Equals(EffectivePermissionKey aObject)
{
return this.ID == aObject.ID && this.OrchardUserID == aObject.OrchardUserID;
}
public override int GetHashCode()
{
// http://stackoverflow.com/a/32502294/3936440
return unchecked(ID.GetHashCode() * 23 * 23 + OrchardUserID.GetHashCode() * 23);
}
public int ID;
public int OrchardUserID;
}
Run Code Online (Sandbox Code Playgroud)
该方法运行时,需要大约5000次递归才能更新所有项目.
最初没有字典需要大约100秒.
使用带有int键的字典替换数据库查询的第一种方法需要22秒 …
我创建了一个界面来尝试进行软删除,混合阴影属性和查询过滤器.但它不起作用.
public interface IDeletableEntity {}
Run Code Online (Sandbox Code Playgroud)
然后在我的模型构建器中
builder.Model.GetEntityTypes()
.Where(entityType => typeof(IDeletableEntity).IsAssignableFrom(entityType.ClrType))
.ToList()
.ForEach(entityType =>
{
builder.Entity(entityType.ClrType).Property<Boolean>("IsDeleted");
builder.Entity(entityType.ClrType).HasQueryFilter(e => EF.Property<Boolean>(e, "IsDeleted") == false);
});
Run Code Online (Sandbox Code Playgroud)
但是查询过滤器的行不能编译.我得到的错误是"无法将lambda表达式转换为'lambda表达式',因为它不是委托类型"
如果我这样做它就会起作用.
builder.Entity<MyEntity>().HasQueryFilter(m => EF.Property<Boolean>(m, "IsDeleted") == false);
Run Code Online (Sandbox Code Playgroud)
有什么方法可以做到这一点?这是为了在每个我想使用软删除实体的实体中都有一个IDeletableEntity接口而不必这样做
提前谢谢了,
我在主菜单中添加了一个新页面,例如Products。现在我想添加一个子页面,例如Sub Products在Products页面下方。我在仪表板中尝试了所有可能的选项,但对我不起作用。任何想法如何处理这个?
谢谢。
我被告知在MVVM中为视图设置DataContext的最佳方法是使用DataTemplate.所以我试图通过使用DataTemplate将MainWindow的DataContext设置为MainWindowViewModel的实例.
我一直无法弄清楚如何.
我已经尝试将ResourceDictionary放在不同的地方(在App.xaml中,在Window.Resources标签中......)
我用谷歌搜索无济于事.这就是我所拥有的......(它不起作用,但在这里它是)
App.xaml中:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
Dictionary1.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DataTemplateTesting" >
<DataTemplate DataType="{x:Type local:MainViewModel}">
<local:MainWindow/>
</DataTemplate>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
MainViewModel.cs
namespace DataTemplateTesting
{
public class MainViewModel
{
public MainViewModel() { }
}
}
Run Code Online (Sandbox Code Playgroud)
我做的唯一另一件事是为MainWindow添加一个处理程序,用于DataContextChanged事件,所以我可以看到它是否曾被激活......它没有.
任何想法如何解决这一问题??
编辑:这里没有任何东西无法生成,但是......这里是MainWindow代码.
MainWindow.xaml
<Window x:Class="DataTemplateTesting.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DataTemplateTesting"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525"
DataContextChanged="Window_DataContextChanged" >
<Grid>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
MainWindow.xaml.cs
namespace DataTemplateTesting
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{ …Run Code Online (Sandbox Code Playgroud) 简单明了,Orchard.Environment.Work<>该类定义的用例是Orchard\Environment\WorkContextModule.cs什么?
它可以在几个地方找到
private readonly Work<IContainerService> _containerService;
public Shapes(Work<IContainerService> containerService) {
_containerService = containerService;
...
Run Code Online (Sandbox Code Playgroud)
这是为了延迟解决IContainerService?
在我遇到问题的各种情况下,我需要检查函数的参数以保证正确的程序流.
我发现创建if-else块只是为了检查nullpointer,数字范围,正确的字符串,正确的对象等等,这变得有点乏味.此外,代码变得更难以阅读,因此获得概述变得更加困难.
所以我想如果在java/javascript/c#...(带有函数的编程语言)中有一种方法可以定义一些前置条件.
所以例如在java中:
void doSomething( int a {0 <= a < 10}, String b {b != "wrong" && b != [1-9]}){
...
}
Run Code Online (Sandbox Code Playgroud)
或类似的东西:
§a: 0 <= a && 10 > a || a == 25 ...
§b: ...
§ifWrongPreConditions: return; //or throw a new default Exception or whatever
void doSomething( int a, String b){
§a: 0 <= a && 10 > a || a == 25 ...
§b: ...
§ifWrongPreConditions: return; //or throw a new default Exception or …Run Code Online (Sandbox Code Playgroud) c# ×7
orchardcms ×3
64-bit ×1
asp.net-mvc ×1
attributes ×1
c++ ×1
data-binding ×1
datacontext ×1
datatemplate ×1
designer ×1
dictionary ×1
ef-core-2.0 ×1
generics ×1
java ×1
javascript ×1
oxite ×1
performance ×1
recursion ×1
struct ×1
syntax ×1
wpf ×1