小编Max*_*kin的帖子

在类中创建私有构造函数有什么用?

为什么我们应该在类中使构造函数私有?因为我们总是需要构造函数是公开的.

oop

126
推荐指数
5
解决办法
7万
查看次数

Windows相当于"不错"

是否有Windows平台上类似Unix命令的,漂亮的

我特意在命令行中查找可以使用的内容,而不是任务管理器中的"设置优先级"菜单.

我在谷歌上发现这种情况的尝试已被那些无法想出更好形容词的人所挫败.

unix windows process-management

68
推荐指数
4
解决办法
3万
查看次数

C结构中的内存对齐

我正在使用32位机器,所以我认为内存对齐应该是4个字节.说我有结构:

typedef struct {
    unsigned short v1;
    unsigned short v2;
    unsigned short v3;
} myStruct;
Run Code Online (Sandbox Code Playgroud)

实际大小是6个字节,我想对齐大小应该是8,但sizeof(myStruct)返回6.

但是,如果我写:

typedef struct {
    unsigned short v1;
    unsigned short v2;
    unsigned short v3;
    int i;
} myStruct;
Run Code Online (Sandbox Code Playgroud)

实际大小是10个字节,对齐是12,这次sizeof(myStruct) == 12.

有人可以解释一下有什么区别吗?

c c++ memory-alignment structure-packing

53
推荐指数
5
解决办法
4万
查看次数

类型参数的C#variance注释,约束为值类型

在C#中可以将方差注释添加到类型参数,约束为值类型:

interface IFoo<in T> where T : struct
{
  void Boo(T x);
}
Run Code Online (Sandbox Code Playgroud)

如果在这种情况下方差注释完全没有意义,为什么编译器允许这样做?

c# compiler-construction generics covariance contravariance

41
推荐指数
1
解决办法
919
查看次数

WPF和WinForms有什么区别?

我正在编写简单的Windows应用程序.我不需要DB支持.为什么我会使用WPF而不是WinForms?

wpf winforms

34
推荐指数
5
解决办法
5万
查看次数

如何使用reflection.emit发出显式接口实现?

请注意以下简单的源代码:

using System;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;

namespace A
{
  public static class Program
  {
    private const MethodAttributes ExplicitImplementation =
      MethodAttributes.Private | MethodAttributes.Virtual | MethodAttributes.Final |
      MethodAttributes.HideBySig | MethodAttributes.NewSlot;
    private const MethodAttributes ImplicitImplementation =
      MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig;

    private static Type EmitMyIntfType(ModuleBuilder moduleBuilder)
    {
      var typeBuilder = moduleBuilder.DefineType("IMyInterface",
        TypeAttributes.NotPublic | TypeAttributes.Interface | TypeAttributes.Abstract);
      typeBuilder.DefineMethod("MyMethod", MethodAttributes.Assembly | MethodAttributes.Abstract |
        MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.NewSlot,
        typeof(void), new[] { typeof(int) });

      return typeBuilder.CreateType();
    }

    public static void Main()
    {
      var …
Run Code Online (Sandbox Code Playgroud)

.net c# reflection reflection.emit explicit-implementation

27
推荐指数
1
解决办法
7969
查看次数

如果有"安腾惨败"背后的技术原因是什么?

这篇文章中, Jonh Dvorak称Itanium是" 过去50年来最伟大的惨败之一 ".虽然他描述了过度乐观的市场预期和这个想法的戏剧性财务结果,但他没有深入探讨这一史诗失败的技术细节.我有机会与Itanium合作一段时间,我个人非常喜欢它的架构,与现代x86处理器架构相比,它是如此清晰,简单和直接......

那么它失败的技术原因是什么?在性能?与x86代码不兼容?编译器的复杂性?为什么这个"Itanic"下沉了?

安腾处理器块

hardware itanium

23
推荐指数
3
解决办法
5359
查看次数

在C#中使用一对(三重等)值作为一个值的最佳方法是什么?

也就是说,我想要一个价值元组.

我心中的用例:

Dictionary<Pair<string, int>, object>
Run Code Online (Sandbox Code Playgroud)

要么

Dictionary<Triple<string, int, int>, object>
Run Code Online (Sandbox Code Playgroud)

是否有内置类型,如Pair或Triple?或者实施它的最佳方式是什么?

更新答案中描述了一些通用元组实现,但对于在字典中用作键的元组,您应该另外验证哈希码的正确计算.在另一个问题中有关于此的更多信息.

更新2我想还值得提醒的是,当你在字典中使用某个值作为键时,它应该是不可变的.

c# generics tuples data-structures

20
推荐指数
5
解决办法
1万
查看次数

结构的大小有char,double,int和at

当我只运行代码片段时

int *t;
std::cout << sizeof(char)   << std::endl;
std::cout << sizeof(double) << std::endl;
std::cout << sizeof(int)    << std::endl;
std::cout << sizeof(t)      << std::endl;
Run Code Online (Sandbox Code Playgroud)

它给我一个这样的结果:

1
8
4
4
Run Code Online (Sandbox Code Playgroud)

总计:17.

但是,当我测试包含这些数据类型的sizeof结构时,它给了我24,我很困惑.额外的7个字节是多少?

这是代码

#include <iostream>
#include <stdio.h>
struct struct_type{
    int i;
    char ch;
    int *p;
    double d;
} s;

int main(){
    int *t;
    //std::cout << sizeof(char)   <<std::endl;
    //std::cout << sizeof(double) <<std::endl;
    //std::cout << sizeof(int)    <<std::endl;
    //std::cout << sizeof(t)      <<std::endl;

    printf("s_type is %d byes long",sizeof(struct struct_type));

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

:编辑

我已经像这样更新了我的代码

#include <iostream> …
Run Code Online (Sandbox Code Playgroud)

c++ structure-packing

20
推荐指数
3
解决办法
7597
查看次数

"做什么!"的目的是什么?F#中的符号?

我是F#的初学者,所以这是一个简单的问题,也许是重复的,但我无法在任何地方找到答案......

我正在阅读这个LOGO DSL实现,我不明白,"do!"是什么意思.这里的符号:

    this.Loaded.Add (fun _ ->
        async {
            do! Async.Sleep 200
            for cmd in theDrawing do
                do! this.Execute(cmd)
        } |> Async.StartImmediate 
    )
Run Code Online (Sandbox Code Playgroud)

你能帮我吗?

f#

19
推荐指数
2
解决办法
7367
查看次数