小编And*_*ndy的帖子

模板是否需要重载构造函数?

我刚看完一些模板视频,我想我错过了一些概念.为什么不调用构造函数,或者为什么在构造函数没有使用所需的数据类型重载时不创建对象?因为我写的<int>不是编译器知道我将要处理一个int?

template <class T>
class Generic {
    T var;
public:
    Generic(){cout << "ctor called " << endl;}
    //Generic (T v) {var = v;}
};


int main () {

    Generic<int> generic1();

}
Run Code Online (Sandbox Code Playgroud)

我不能创建这样的对象然后通过setter修改T var的值吗?为什么我需要重载的构造函数,例如 Generic<int> generic1(9);

c++ templates

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

创建流程时崩溃

我试图在C++中使用msdn函数(CreateProcess)来运行应用程序.我没有得到任何错误,但是当我运行它时,它会崩溃.我做了什么也注意到它创建了一个进程,但它没有运行它应该的文本文件.

我的代码:

#include <windows.h>
#include <iostream>
#include <string>

using namespace std;

void createPro ();

int main()
{
    createPro();
}

void createPro () {

    LPCTSTR lpApplicationName = "C:/Users/Andyy/Desktop/hello.txt";

    LPSTARTUPINFO lpStartupInfo;
    LPPROCESS_INFORMATION lpProcessInfo;

    memset(&lpStartupInfo, 0, sizeof(lpStartupInfo));
    memset(&lpProcessInfo, 0, sizeof(lpProcessInfo));


    if (!CreateProcess(lpApplicationName,
                   NULL, NULL, NULL,
                   NULL, NULL, NULL, NULL,
                   lpStartupInfo,
                   lpProcessInfo
                  )
   ) {
    cout << "Failed to create process" << lpApplicationName << endl;
}

    cout << "Program exec: " << lpApplicationName << endl;
}
Run Code Online (Sandbox Code Playgroud)

它创建了进程,但无法运行文本文件,并且编译器中没有显示错误.提前致谢.返回错误:进程返回-1073741819(0xC0000005)

c++ windows winapi

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

如何将const char*附加到const char*

我试图将三个不同的const char*变量附加到一个变量中.这是因为来自windows库的函数采用参数LPCTSTR.我有以下代码:

const char* path = "C:\\Users\\xxx\\Desktop\\";
const char* archivo = "vectors";
const char* extension = ".txt";

const char* fullPath =+ path;
fullPath =+ archivo;
fullPath =+ extension;
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我只获得添加到FullPath的最后一个(扩展名).

c++

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

只保留记事本++中每行的第一个单词

例如我有:

hello I am ...
For the reason ...
Not sure if ...
Run Code Online (Sandbox Code Playgroud)

我想保留helloForNot摆脱记事本++中每一行中的其余部分。

regex notepad++

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

标签 统计

c++ ×3

notepad++ ×1

regex ×1

templates ×1

winapi ×1

windows ×1