小编Cut*_*ert的帖子

c ++通过引用将映射传递给函数

如何将mapby 传递reference给函数?Visual Studio 2010给了我一个unresolved externals错误.目前,我有以下简化代码:

void function1(){
    map<int, int> * my_map = new map<int, int>(); 
    function2(*my_map); 
}

void function2(map<int, int> &temp_map){
    //do stuff with the map
}
Run Code Online (Sandbox Code Playgroud)

这里有类似问题的几个答案,但是他们使用typedef并添加std::到定义的开头,但我真的不确定原因.

int ComputerPlayer::getBestMoves(){
    //will return the pit number of the best possible move. 

    //map to hold pit numbers and rankings for each possible pit number.
    //map<pitNumber, rank> only adds pit numbers to map if they have seeds in them.

    std::map<int, int> possiblePits; //map …
Run Code Online (Sandbox Code Playgroud)

c++ map pass-by-reference

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

在C++中使用函数名前的&符号的含义?

举个例子:

inline string &GetLabel( ) {
        return m_Label;
};
Run Code Online (Sandbox Code Playgroud)

其中m_Label是私有类成员变量.

我认为我理解它的方式,这个函数将返回对变量m_Label的引用.在我的整个程序中使用它会有什么影响,并且返回值而不是引用会更好吗?谢谢!

c++ pointers function pass-by-reference

11
推荐指数
2
解决办法
8761
查看次数

将批量数据索引到ElasticSearch的首选方法?

我一直在关注ElasticSearch作为解决方案在我公司获得更好的搜索和分析功能.我们目前所有的数据都在SQL Server中,并且我已经成功安装了JDBC River并将一些测试数据输入ES.

Rivers似乎可以在将来的版本中弃用,JDBC河由第三方维护.Logstash似乎还不支持从SQL Server编制索引(不知道它是否是计划的功能).

因此,对于我想将数据从SQL Server移动到ElasticSearch的情况,当SQL使用新数据更新时,索引数据和维护索引的首选方法是什么?

从链接的线程:

我们建议您在ES之外拥有索引流程,并确保它可以根据您的需求进行扩展.

我不太清楚从哪里开始.是否使用ES提供的API之一?

sql-server elasticsearch elasticsearch-jdbc-river

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

使用Clickonce部署Microsoft.Bcl.Async

我有一个VB.NET应用程序崩溃与以下错误:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Threading.Tasks, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'System.Threading.Tasks, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

我正在尝试使用Microsoft.Bcl.Async库.我通过Nuget在实际使用Async/Await调用的项目和引用它的项目上安装了它.一切都在我的计算机上完美运行,但是当我在另一台计算机上发布和测试时,当我尝试使用其中使用Async/Await的部分时,我的程序崩溃了.

在Copy Local设置为true的两个项目中引用System.Threading.Tasks.在Copy Local设置为true的两个项目中引用Microsoft.Threading.Tasks.我已经看到关于这个的另一个线程,它已安装在相关项目中.这些是我的app.config文件中包含的行:

  <dependentAssembly>
    <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
  </dependentAssembly>
Run Code Online (Sandbox Code Playgroud)

设置这个我错过了什么?如果您需要更多信息,请告诉我.谢谢!

.net vb.net asynchronous base-class-library

6
推荐指数
2
解决办法
1593
查看次数

在C#中使用多线程锁定DataTable的正确方法?

这是锁定和修改DataTable多个线程共享的正确方法吗?如果没有,那么正确的做法是什么?

private void DoGeocodeLookup(object info)
{
    ParameterRow data = (ParameterRow)info;
    DataRow dr = data.Dr;
    int localIndex = data.Index;
    ManualResetEvent doneEvent = data.m_doneEvent; 

    Geocode_Google.GeoCode gc = new GeoCode();

    gc.Addr_In = m_dtAddress.Rows[localIndex]["AddressStd_tx"].ToString();

    gc.GeoCodeOne();

    if (gc.Status == "OK")
    {
        //write back to temporary datatable
        lock( m_TempTable.Rows.SyncRoot )
        {
            m_TempTable.Rows[localIndex]["GL_Address"] = gc.Thoroughfare_tx; 
        }
    }
    doneEvent.Set(); 
}
Run Code Online (Sandbox Code Playgroud)

我的结构:

struct ParameterRow
{
    private DataRow m_row;
    private int m_index;

    public DataRow Dr
    {
        get { return m_row; }
        set { m_row = value; }
    } …
Run Code Online (Sandbox Code Playgroud)

c# datatable multithreading

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

在C#中正确使用Parallel for循环?

在这个例子中,Parallel.For如果我想将一次可以执行该函数的线程数限制DoWork为十个,那么这是否正确使用了循环?在十个线程中的一个可用之前,是否会阻塞其他线程?如果没有,什么是更好的多线程解决方案,仍然可以让我执行6000次以上的功能?

class Program
{
    static void Main(string[] args)
    {
        ThreadExample ex = new ThreadExample(); 
    }
}

public class ThreadExample
{
    int limit = 6411; 

    public ThreadExample()
    {
        Console.WriteLine("Starting threads...");
        int temp = 0; 
        Parallel.For(temp, limit, new ParallelOptions { MaxDegreeOfParallelism = 10 }, i =>
        {
            DoWork(temp);
            temp++; 
        }); 
    }

    public void DoWork(int info)
    {
        //Thread.Sleep(50); //doing some work here. 

        int num = info * 5; 

        Console.WriteLine("Thread: {0}      Result: {1}", info.ToString(), num.ToString());
    }
}
Run Code Online (Sandbox Code Playgroud)

c# multithreading

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

获取当前登录的Windows用户?

可能重复:
如何在Active Directory中获取用户组?(c#,asp.net)

有没有办法使用System.DirectoryServices.AccountManagement命名空间获取当前登录的用户?我一直在使用以下内容:

    Dim wi As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent()

    Dim fullName As String = wi.Name.ToString

    Dim loggedOnUser = fullName.Substring(fullName.IndexOf("\") + 1)

    Console.WriteLine("The currently logged on user is {0}", loggedOnUser)
Run Code Online (Sandbox Code Playgroud)

但我想了解有关当前用户的更多信息,例如它们所属的组名称,并且想知道AccountManagement命名空间是否提供了此信息.

使用它只返回我无法理解的数字字符串:

For Each item As IdentityReference In wi.Groups
    Console.WriteLine(item.ToString())
Next
Run Code Online (Sandbox Code Playgroud)

.net windows winforms

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

什么时候VB.NET中的模块变量被实例化?

我想知道在程序的生命周期中,模块中的变量将在此示例中初始化:

Module Helper
    Friend m_Settings As New UserSettings()

    Sub Foo()
        '...
    End Sub

    Sub Bar()
        '...
    End Sub

End Module

Public Class UserSettings
    Public Property UserName As String
    Public Property PrefServer As Integer

    Public Sub New()
        '...
    End Sub

    Public Sub LoadSettings()
        '...
    End Sub
End Class
Run Code Online (Sandbox Code Playgroud)

什么时候会m_Settings被初始化?我可以在构造函数中设置一个断点UserSettings并查看调用堆栈,但我看到"外部代码",但这并没有告诉我很多.

vb.net global-variables

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

Parallel For不会在静态构造函数中导致死锁吗?

我试图将线程添加到我所拥有的静态类中,并遇到了一堆问题.我读了这个帖子和它链接到的博客文章,我想我明白了发生了什么.但我无法弄清楚为什么Parallel For循环仍然像在这个例子中那样工作:

using System;
using System.Threading;
using System.Threading.Tasks; 

namespace ThreadingTest
{
    public static class TestClass
    {
        public static int AwesomeNum = 43; 

        static TestClass()
        {
            string[] x = { "deal", "witch", "panda"};

            //does not cause a deadlock? huh?
            Parallel.For(0, x.Length,  i =>
                {
                    Console.WriteLine(x[i]); 
                });

            //results in a deadlock
            //Parallel.Invoke(writesomething, writesomethingelse); 

            //results in deadlock
            Thread thread = new Thread(new ThreadStart(() =>
            {
                Console.WriteLine("there is a bear in my soup"); 
            }));

            thread.Start();
            thread.Join(); 
        }

        private static void writesomething()
        { …
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading

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

用于在 Word 文档中查找和替换文本的 VB 脚本

我对 VB 脚本编写没有太多经验,但我正在尝试编写一些东西,在 Word 文档中搜索特定字符串,将其替换为我指定的任何内容,然后在标签打印机上打印出来。

它可以很好地完成第一次替换,但不能完成第二次替换。有人可以看看我可能做错了什么吗?

Option Explicit

Dim WordApp
Dim WordDoc
Dim strReadCompName
Dim strReadCompSN

Set WordApp = CreateObject("Word.Application")
WordApp.Visible = TRUE

WordApp.Documents.Open("C:\LabelTemplate.doc")
WordApp.Documents("LabelTemplate.doc").Activate

Set WordDoc = WordApp.ActiveDocument

strReadCompName = InputBox("Enter Computer Name", "Name")
strReadCompSN = InputBox("Enter Serial Number", "Serial")

With WordApp.Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .MatchWholeWord = TRUE
    .Text = "nametext"
    .Execute ,,,,,,,,,strReadCompName
End With

With WordApp.Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .MatchWholeWord = TRUE
    .Text = "serialtext"
    .Execute ,,,,,,,,,strReadCompSN
End With

WordDoc.PrintOut()
WordDoc.Saved = TRUE
WordApp.Quit
Run Code Online (Sandbox Code Playgroud)

vbscript ms-word

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

C++静态变量和未解析的外部错误

我希望我能对类的静态变量做一些澄清.

例如:我有两个不同的类,它们执行完全不同的功能,alpha和beta.在alpha中,我声明了一个beta类型的静态变量,所以它看起来像这样:

//alpha.h

#pragma once
#include <iostream>
#include "beta.h"

class alpha{
public: 
    alpha(){

    }

    static beta var; 

    void func(){
        var.setX(3);
    }

    void output(){

    }
};

//beta.h

#pragma once
#include <iostream>
using namespace std; 

class beta{

public: 

    int x; 
    char y; 

    beta(){
        x = 0; 
        y = ' '; 
    }

    void setX(int _X){
        x = _X; 
    }

};

//main.cpp

#include <iostream>
#include <iomanip>
#include "alpha.h"
using namespace std; 

int main(){
    alpha x, y, z; 
    x.func(); 
}
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试编译它时,我得到一个未解决的外部错误:

错误LNK2001:未解析的外部符号"public:static class beta alpha …

c++ static class linker-errors

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

通过Windows窗体迭代并关闭它们?

我正在尝试使用以下代码迭代我的应用程序中的所有当前打开的表单,并关闭它们除了主表单作为清理的一部分.

    Dim openForms As Windows.Forms.FormCollection = Application.OpenForms

    For Each frm As Windows.Forms.Form In openForms
        If frm.Name.ToString() <> "FrmMainNew" Then
            frm.Close()
        End If
    Next
Run Code Online (Sandbox Code Playgroud)

但是,我得到的是InvalidOperationException因为frm.Close()执行时,openForms删除了的条目,更改了集合的大小.我显然做错了,所以如果有人能指出我这里的问题,那就太棒了.否则,有没有其他方法可以做这样的事情?

vb.net foreach winforms

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