小编par*_*mar的帖子

选择了错误的功能

我试图清理使用一些代码char*std::string跑进由下面的代码所示的问题.

void Foo( int xIn , const std::string & fooIn )
{
    std::cout << "string argument version called \n";
}

void Foo( int xIn ,  bool flagIn = true )
{
    std::cout << "bool argument version called \n";
}

int main()
{
    int x = 1;
    Foo( x , "testing" );
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我运行程序时,我得到bool参数版本调用.是一个char*bool转换优于char*const std::string&或Visual Studio 2008中捉弄我吗?

c++ visual-c++

26
推荐指数
2
解决办法
548
查看次数

vb.net中的List.ForEach - 令我困惑

请考虑以下代码示例:

    TempList.ForEach(Function(obj)
        obj.Deleted = True
    End Function)
Run Code Online (Sandbox Code Playgroud)

还有这个:

    TempList.ForEach(Function(obj) obj.Deleted = True)
Run Code Online (Sandbox Code Playgroud)

我希望结果是相同的,但第二个代码示例不会更改列表TempList中的对象.

这篇文章更能理解为什么......?或者至少得到一些帮助,了解为什么......

vb.net foreach generic-list

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

析构函数被认为是const函数吗?

考虑一下

class Foo
{
public:
    Foo(){}
    ~Foo(){}
    void NonConstBar() {}
    void ConstBar() const {}
};

int main()
{
    const Foo* pFoo = new Foo();
    pFoo->ConstBar(); //No error
    pFoo->NonConstBar(); //Compile error about non const function being invoked
    delete pFoo; //No error 

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

在main函数中,我调用了Foo的const非const函数

试图调用任何非const函数会在Visual Studio中产生错误,就像这样

error C2662: 'Foo::NonConstBar' : cannot convert 'this' pointer from 'const Foo' to 'Foo &'

delete pFoo不会发出任何此类错误.delete语句必然会调用没有const修饰符的Foo类的析构函数.析构函数也允许调用其他非const成员函数.那么它是一个const函数吗?或者是在const指针上删除一个特殊的异常?

c++ destructor

22
推荐指数
2
解决办法
3136
查看次数

动态库是否打破了C++标准?

C++标准3.6.3规定

静态持续时间的初始化对象的析构函数被调用为从main返回并且由于调用exit而返回的结果

在Windows上你有FreeLibrary和linux你有dlclose来卸载一个动态链接的库.你可以在从main返回之前调用这些函数.

卸载共享库的一个副作用是运行库中定义的静态对象的所有析构函数.

这是否意味着它违反了C++标准,因为这些析构函数已经过早运行了?

c++ dll shared-libraries language-lawyer

21
推荐指数
4
解决办法
1728
查看次数

为什么linq-2-sql会创建额外的不必要对象?

我在数据库中有一个简单的Parent Child表

CREATE TABLE [Parent](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](256) NOT NULL)    
ALTER TABLE [Parent] ADD CONSTRAINT [PK_Parent_Id] PRIMARY KEY ([Id])    

CREATE TABLE [Child](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [ParentId] [int] NOT NULL,
    [Name] [nvarchar](256) NOT NULL)    
ALTER TABLE [Child] ADD CONSTRAINT [PK_Child_Id] PRIMARY KEY ([Id])
ALTER TABLE [Child] ADD CONSTRAINT [FK_Child_Parent_ID] 
    FOREIGN KEY([ParentId]) REFERENCES [Parent] ([Id])
Run Code Online (Sandbox Code Playgroud)

我在其中的数据是

父表

Id  Name
1   John
Run Code Online (Sandbox Code Playgroud)

儿童表

Id ParentId  Name
1     1    Mike
2     1    Jake
3     1    Sue
4     1 …
Run Code Online (Sandbox Code Playgroud)

.net c# linq orm linq-to-sql

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

即使进程尚未退出,进程的性能计数器实例名称是否也会更改

我正在使用这个类作为一类测试的基类,这些测试启动一个进程并给它一些输入,并在给它更多输入之前等待它变为空闲.

public abstract class TestProcessLaunchingBase
{
    protected PerformanceCounter PerfCounter { get; set; }

    protected void WaitForProcessIdle()
    {
        while (true)
        {
            float oldValue = PerfCounter.NextValue();

            Thread.Sleep(1000);

            float nextValue = PerfCounter.NextValue();

            if (nextValue == 0)
                break;
        }
    }

    protected void FindSpawnedProcessPerfCounter(int processId)
    {
        PerformanceCounterCategory cat = new PerformanceCounterCategory("Process");
        string[] instances = cat.GetInstanceNames();
        foreach (string instance in instances)
        {
            using (PerformanceCounter cnt = new PerformanceCounter("Process", "ID Process", instance, true))
            {
                int val = (int)cnt.RawValue;
                if (val == processId)
                {
                    PerfCounter = new PerformanceCounter("Process", …
Run Code Online (Sandbox Code Playgroud)

c#

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

如何让perl -c抛出Undefined或Undeclared函数错误?

从C++背景的,我虔诚地使用use strictuse warningsPerl的特点:

#!/usr/bin/perl -w
use strict;
use warnings;

$foo = 1; #Throws "$foo" requires explicit package name error

foobar( 1 );  
Run Code Online (Sandbox Code Playgroud)

use strict错误输入变量名称时,该构造非常有助于捕获错误.是否有一个等效的构造来捕获错误的函数名称?在上面的例子中,如果有类似的perl -c事情发现没有foob​​ar 函数可以调用那将是很好的.当然,运行脚本会抛出一个Undefined子例程错误,但我想早点抓住它.

perl

10
推荐指数
3
解决办法
1516
查看次数

将-1转换为无符号类型

请考虑以下代码来设置x的所有位

unsigned int x = -1;
Run Code Online (Sandbox Code Playgroud)

这是便携式吗?它似乎至少适用于Visual Studio 2005-2010

c++

9
推荐指数
3
解决办法
340
查看次数

如何在silverlight导航应用程序中检测后退按钮或前进按钮导航

当页面导航到silverlight时,您可以覆盖此方法.

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
}
Run Code Online (Sandbox Code Playgroud)

所述NavigationEventArgs具有NavigationMode其被定义为列举

public enum NavigationMode
{
    New = 0,
    Back = 1,
    Forward = 2,
    Refresh = 3,
}
Run Code Online (Sandbox Code Playgroud)

但是打电话e.NavigationMode总是抛出一个NotImplementedException

在Silverlight中是否有办法检测正在导航的页面,因为用户点击了前进/后退浏览器按钮.

我想要实现的是当用户点击后退按钮时可以保留的某种状态.

例如,假设您有一个客户页面,其中显示了数据网格中的客户列表.用户可以选择客户,并且有一个详细视图,显示该客户的所有订单.现在,在订单商品中,您可以单击超链接链接,该链接将您带到订单的发货历史记录,该订单是单独的页面.当用户点击后退按钮时,我想返回客户页面并自动选择他正在查看的客户.这有可能吗?

我还尝试了片段导航功能

NavigationService.Navigate(new Uri("#currentcustomerid=" 
       + customer.Id.ToString(), UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)

当客户选择更改时,但当用户单击客户页面上的各种客户时,这会为历史记录添加太多项目.

编辑

还有一种方法可以覆盖

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
}
Run Code Online (Sandbox Code Playgroud)

这与BugFinder的答案所指示的处理NavigationService.Navigating事件相同.在此方法中,当您按下后退或前进按钮时e.NavigationMode始终返回New.此方法返回的唯一时间Back是显式调用NavigationService.GoBack()

.net c# silverlight silverlight-5.0

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

使用带有 put 的 unirest 文件发送时获取 ERR_FS_FILE_TOO_LARGE

我正在使用 unirest 上传这样的文件

 unirest.put(fullUri)
    .auth({
      user: self.userName,
      pass: self.password
    })
    .header('X-Checksum-Sha1', sha1Hash)
    .header('X-Checksum-Md5', md5Hash)
    .send(fs.readFileSync(filePath))
    .end(function (response) {
Run Code Online (Sandbox Code Playgroud)

这适用于较小的文件,但对于大文件,我收到 ERR_FS_FILE_TOO_LARGE 错误。我已经尝试过max_old_space_size但没有成功。看起来我可以通过流式传输文件来解决这个问题,但是我在 unirest js 库中找不到一个 api 来做到这一点。

javascript node.js unirest

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