问题列表 - 第7186页

将映射值复制到STL中的向量

目前通过Effective STL工作.第5项建议通常最好将范围成员函数用于它们的单个元素对应物.我目前希望将地图中的所有值(即 - 我不需要键)复制到矢量.

最干净的方法是什么?

c++ containers stl

72
推荐指数
7
解决办法
9万
查看次数

这个C++堆栈分配器的改进?

对基于堆栈的分配器的任何建议?(除了建议使用私人/公共成员的课程)

struct Heap
{
    void* heap_start;
    void* heap_end;
    size_t max_end;

    Heap(size_t size)
    {
        heap_start = malloc(size);
        heap_end = heap_start;
        max_end = size + (size_t) heap_start;
    }

    ~Heap()
    {
        ::free(heap_start);
    }

    void* allocate(size_t bytes)
    {

        size_t new_end = ((size_t) heap_end) + bytes;

        if( new_end > max_end )
            throw std::bad_alloc();

        void* output = heap_end;
        heap_end = (void*) new_end;
        return output;
    }

}
Run Code Online (Sandbox Code Playgroud)

c++ memory memory-management

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

无法将参数值从TimeSpan转换为DateTime

我正在使用SQL Server 2008.

首先,我给出SqlDbType.TimeSystem.TimeSpanInsert和Update的参数类型.

我成功了.

现在我改为DbType.Time而不是SqlDbType.Time.这给了我错误消息"无法将参数值从TimeSpan转换为DateTime"没有调用"过程"

sql-server ado.net datetime

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

在Access中使用自动编号 - INSERT语句

我无法运行一个INSERT声明,其中有一个自动编号作为PK字段.我有一个自动递增long作为主键,然后4个字段的类型double; 而Access(使用ADO)似乎需要insert语句的五个值.

INSERT INTO [MY_TABLE] VALUES (1.0, 2.0, 3.0, 4.0);
>> Error: Number of query values and destinations fields are not the same.

INSERT INTO [MY_TABLE] VALUE (1, 1.0, 2.0, 3.0, 4.0);
>> Success!!
Run Code Online (Sandbox Code Playgroud)

如何使用自动编号实际自动编号?

sql ms-access ado insert autonumber

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

在使用DataContext.ExecuteQuery时,LINQ to SQL可以填充非ColumnAttribute标记的属性吗?

鉴于此表:

CREATE TABLE [Comments]
(
  [Id] [int] IDENTITY(1, 1) NOT NULL, 
  [Text] [nvarchar](600) NOT NULL
)
Run Code Online (Sandbox Code Playgroud)

有了这个模型类:

[Table(Name="Comments")]
public class Comment
{
    [Column(AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
    public int Id { get; set; }

    [Column(DbType = "NVarChar(600) NOT NULL", CanBeNull = false)]
    public string Text { get; set; }

    public string ArbitraryText { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

ArbitraryText使用该ExecuteQuery方法时,DataContext是否可以填充属性:

var comments = db.ExecuteQuery<Comment>("select Id, [Text], 'hello' [ArbitraryText] from …
Run Code Online (Sandbox Code Playgroud)

c# linq-to-sql

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

C++ Style Convention:类声明中的参数名称

我是一个相当新的C++程序员,我想在类声明中听到支持和反对命名参数的参数.


这是一个例子:

Student.h

#ifndef STUDENT_H_
#define STUDENT_H_

#include <string>

using namespace std;

class Student
{
    private:
        string name;
        unsigned int age;
        float height, GPA;

    public:
        Student(string, unsigned int, float, float);

        void setAge(unsigned int);
};

#endif /*STUDENT_H_*/
Run Code Online (Sandbox Code Playgroud)

#ifndef STUDENT_H_
#define STUDENT_H_

#include <string>

class Student
{
    private:
        string name;
        unsigned int age;
        float height, GPA;

    public:
        Student(string name, unsigned int age, float height, float GPA);

        void setAge(unsigned int age);
};

#endif /*STUDENT_H_*/
Run Code Online (Sandbox Code Playgroud)

Student.cpp

#include "Student.h"

Student::Student(   string name,
            unsigned int …
Run Code Online (Sandbox Code Playgroud)

c++ parameters coding-style naming-conventions

5
推荐指数
2
解决办法
5314
查看次数

UIWebView的cookie存储在哪里?

我正在构建一个带有cookie的iPhone应用程序.在Safari设置中删除Cookie不会删除它们.它们存放在哪里?是否可以从另一个UIWebView读取它们?

谢谢!

iphone cookies

97
推荐指数
2
解决办法
7万
查看次数

C++ 0x的哪些功能肯定会保留(如果有的话)?

是否有任何C++ 0x的功能可以肯定存在?也许,标准库中的线程?

c++ language-features language-lawyer c++11

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

反思有多慢

我最近创建了一个接口层来区分DataAccessProvider和业务逻辑层.通过这种方法,我们可以随时通过更改Web/App.Config中的值来更改DataAccessProvider的选择.(如果需要,可以给出更多细节).

无论如何,要做到这一点,我们使用反射来完成我们可以工作的DataProvider类.

/// <summary>
/// The constructor will create a new provider with the use of reflection.
/// If the assembly could not be loaded an AssemblyNotFoundException will be thrown.
/// </summary>
public DataAccessProviderFactory()
{
    string providerName = ConfigurationManager.AppSettings["DataProvider"];
    string providerFactoryName = ConfigurationManager.AppSettings["DataProviderFactory"];
    try
    {
        activeProvider = Assembly.Load(providerName);
        activeDataProviderFactory = (IDataProviderFactory)activeProvider.CreateInstance(providerFactoryName);
    }
    catch
    {
        throw new AssemblyNotFoundException();
    }
}
Run Code Online (Sandbox Code Playgroud)

但现在我想知道反思有多缓慢?

c# reflection performance assemblies

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

如何以编程方式配置WCF已知类型?

我的客户端/服务器应用程序正在使用WCF进行通信,这非常棒.然而,当前架构的一个缺点是我必须对某些传输类型使用已知类型配置.我正在使用内部的Pub/Sub机制,这个要求是不可避免的.

问题是很容易忘记添加已知类型,如果你这样做,WCF会无声地失败,只有很少的线索可以解决出错的问题.

在我的应用程序中,我知道将要发送的类型集.我想以编程方式执行配置,而不是声明性地通过App.config当前包含这样的内容的文件:

<system.runtime.serialization>
  <dataContractSerializer>
    <declaredTypes>
      <add type="MyProject.MyParent, MyProjectAssembly">
        <knownType type="MyProject.MyChild1, MyProjectAssembly"/>
        <knownType type="MyProject.MyChild2, MyProjectAssembly"/>
        <knownType type="MyProject.MyChild3, MyProjectAssembly"/>
        <knownType type="MyProject.MyChild4, MyProjectAssembly"/>
        <knownType type="MyProject.MyChild5, MyProjectAssembly"/>
      </add>
    </declaredTypes>
  </dataContractSerializer>
</system.runtime.serialization>
Run Code Online (Sandbox Code Playgroud)

相反,我想做这样的事情:

foreach (Type type in _transmittedTypes)
{
    // How would I write this method?
    AddKnownType(typeof(MyParent), type);
}
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下我怎么做这个吗?

编辑请理解我正在尝试在运行时动态设置已知类型,而不是在配置中使用声明或使用源代码中的属性.

这基本上是关于WCF API的问题,而不是样式问题.

编辑2 此MSDN页面指​​出:

您还可以向ReadOnlyCollection添加类型,通过DataContractSerializer的KnownTypes属性访问.

不幸的是,只要KnownTypes是一个只读属性,并且属性的值是a,它就会说并且它没有多大意义ReadOnlyCollection.

.net wcf wcf-configuration known-types

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