问题列表 - 第9690页

实现operator []时,如何包含边界检查?

首先,我为这个简单问题的漫长导致道歉.

我正在实现一个类,它在空间填充曲线上作为非常长的1维索引,或者表示索引对应的笛卡尔坐标的n元组.

class curvePoint
{
public:
    friend class curveCalculate;

    //Construction and Destruction
    curvePoint(): point(NULL), dimensions(0) {}
    virtual ~curvePoint(){if(point!=NULL) delete[] point;}

    //Mutators
    void convertToIndex(){ if(isTuple()) calc(this); }
    void convertToTuple(){ if(isIndex()) calc(this); }
    void setTuple(quint16 *tuple, int size);
    void setIndex(quint16 *index, int size);
    void setAlgorithm(curveType alg){algorithm = alg;}

    //Inspectors
    bool isIndex(){return current==Index;}
    bool isTuple(){return current==Tuple;}
    size_t size(){return dimensions;}
    quint16 operator[](size_t index);

    enum curveType{HilbertCurve, ZCurve, GrayCodeCurve};
    enum status{Index, Tuple};

private:
    curveCalculate calc;
    curveType algorithm;
    quint16 *point;
    size_t dimensions;
    status current;
};
Run Code Online (Sandbox Code Playgroud)

(点指向 …

c++ operator-overloading

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

C#中的List.Sort:使用null对象调用comparer

我使用内置的C#List.Sort函数和自定义比较器得到奇怪的行为.

出于某种原因,它有时会将comparer类的Compare方法与null对象作为参数之一进行调用.但是,如果我使用调试器检查列表,则集合中没有空对象.

我的比较器类看起来像这样:

public class DelegateToComparer<T> : IComparer<T>
{
    private readonly Func<T,T,int> _comparer;

    public int Compare(T x, T y)
    {
        return _comparer(x, y);
    }

    public DelegateToComparer(Func<T, T, int> comparer)
    {
        _comparer = comparer;
    }
}
Run Code Online (Sandbox Code Playgroud)

这允许委托传递给List.Sort方法,如下所示:

mylist.Sort(new DelegateToComparer<MyClass>(
    (x, y) => { 
         return x.SomeProp.CompareTo(y.SomeProp); 
     });
Run Code Online (Sandbox Code Playgroud)

因此,即使没有mylist的元素为null,上面的委托也会为x参数抛出一个空引用异常.

更新:是的我绝对相信它是参数x抛出空引用异常!

更新:我没有使用框架的List.Sort方法,而是尝试了一种自定义排序方法(即新的BubbleSort().排序(mylist)),问题就消失了.正如我所怀疑的,List.Sort方法由于某种原因将null传递给比较器.

c# sorting list

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

处理z-index'd图层上的点击事件

我正在构建的地图应用程序中有2个z-index图层.单击要放大的图层时出现问题.单击处理程序位于基础z-index图层上,我不希望在单击上层图层中的控件时触发它.

我遇到的问题是,无论什么事情都会引发事件,但是当点击顶层的某些内容时,事件的originalTarget属性不是底层图像.反正有改变吗?

javascript z-index event-handling

7
推荐指数
1
解决办法
3万
查看次数

如何分析二进制文件?

我有一个二进制文件.我不知道它是如何格式化的,我只知道它来自delphi代码.

是否存在分析二进制文件的任何方式?

是否存在任何"模式"来分析和反序列化具有未知格式的文件的二进制内容?

binary serialization code-analysis reverse-engineering

26
推荐指数
6
解决办法
6万
查看次数

如何在JavaScript中创建字符串大写的第一个字母?

如何将字符串的第一个字母设为大写,但不更改任何其他字母的大小写?

例如:

  • "this is a test" - > "This is a test"
  • "the Eiffel Tower" - > "The Eiffel Tower"
  • "/index.html" - > "/index.html"

javascript string letter capitalize

3565
推荐指数
79
解决办法
188万
查看次数

找不到WCF绑定错误?

我使用的是VSTS 2008 + C#+ .Net 3.0.我正在使用自托管的WCF.执行以下语句时,会出现以下绑定未找到错误.我发布了我的整个app.config文件,任何想法有什么问题?

ServiceHost host = new ServiceHost(typeof(MyWCFService));
Run Code Online (Sandbox Code Playgroud)

错误信息,

Configuration binding extension 'system.serviceModel/bindings/MyBinding' could not be found. Verify that this binding extension is properly registered in system.serviceModel/extensions/bindingExtensions and that it is spelled correctly.
Run Code Online (Sandbox Code Playgroud)

完整的app.config,

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="MyBinding"
            closeTimeout="00:00:10"
            openTimeout="00:00:20"
            receiveTimeout="00:00:30"
            sendTimeout="00:00:40"
            bypassProxyOnLocal="false"
            transactionFlow="false"
            hostNameComparisonMode="WeakWildcard"
            maxReceivedMessageSize="100000000"
            messageEncoding="Mtom"
            proxyAddress="http://foo/bar"
            textEncoding="utf-16"
            useDefaultWebProxy="false">
          <reliableSession ordered="false"
               inactivityTimeout="00:02:00"
               enabled="true" />
          <security mode="Transport">
            <transport clientCredentialType="Digest"
               proxyCredentialType="None"
               realm="someRealm" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="MyWCFService"
                behaviorConfiguration="mexServiceBehavior">
        <host>
          <baseAddresses>
            <add …
Run Code Online (Sandbox Code Playgroud)

c# wcf binding visual-studio-2008

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

如何通过代码配置ASP.Net成员资格提供程序?

我们正在使用ASP.Net成员资格提供程序(SQL Server提供程序),我希望能够将Admin用户帐户设置为安装程序的一部分.为此,我需要配置ASP.Net成员资格提供程序,以便我的安装程序可以使用它 - 但我不想为安装程序设置配置文件.

那么有没有一种方法可以通过代码配置ASP.Net成员资格而无需编写自定义提供程序?

c# asp.net windows-installer asp.net-membership

6
推荐指数
1
解决办法
5348
查看次数

Vimperator推荐设置

通过对Vim的研究,我最近开始为Firefox使用Vimperator插件.

因此,如果有推荐的设置,请教它.

vim firefox vimperator

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

使用jQuery UI而不是插件有什么好处?

jQuery 1.3.2缩小为55.9K,jQuery UI核心本身有超过110K,并且每个组件的顶部都增加了更多的核心.

我想知道在插件上使用jQuery UI的充分理由.

例如jQuery手风琴插件只有3.8K,手风琴,工具提示,标签,可滚动,叠加和曝光的jQuery Tools只有5.8K,jQuery拖放插件总共4.8K等.

使用UI而不是使用这些插件有什么好处?是否值得为您的用途添加超过110k +?

如果是这样,为什么要使用它?

你可以发布你使用jQuery UI的原因以及你不使用它的原因吗?

jquery jquery-ui jquery-plugins

27
推荐指数
3
解决办法
4653
查看次数

MVC索引页面和过滤器

这似乎是一个非常简单的问题,但我迷路了,需要一些指示.

我正在使用ASP.NET MVC C#,并有一个索引页面显示项目列表,这是正常的.

现在我正在尝试添加DropDownList,这取决于用户选择的内容将过滤项目列表.但我一直在想如何使用RunAt Server在ASP.NET Web中执行此操作,我知道这是错误的.

任何指针都会受到欢迎.

asp.net-mvc

6
推荐指数
1
解决办法
2614
查看次数