我刚看完一些模板视频,我想我错过了一些概念.为什么不调用构造函数,或者为什么在构造函数没有使用所需的数据类型重载时不创建对象?因为我写的<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++中使用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)
我试图将三个不同的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的最后一个(扩展名).
例如我有:
hello I am ...
For the reason ...
Not sure if ...
Run Code Online (Sandbox Code Playgroud)
我想保留hello和For并Not摆脱记事本++中每一行中的其余部分。