我知道所有关于指针和&符号的意思是"地址",但在这种情况下它意味着什么?
另外,当重载运算符时,为什么通常用const声明参数?
例如,一个名为Table的类,其构造函数为:
Table(string name="", vector <string> mods);
如何将矢量初始化为空?
编辑:忘记提到这是C++.
当你去删除指针时,第一个例子不起作用.当我添加null终止符时,程序要么挂起,要么没有它我得到:
Debug Assertion Failed Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) 来自Visual Studio 2008
//Won't work when deleting pointer:
char *at = new char [3];
at = "tw"; // <-- not sure what's going on here that strcpy does differently
at[2] = '\0'; // <-- causes program to hang
delete at;
//Works fine when deleting pointer:
char *at = new char [3];
strcpy(at,"t");
at[1] = 'w';
at[2] = '\0';
delete at;
Run Code Online (Sandbox Code Playgroud)
那么当我使用双引号而不是strcpy时会发生什么?它们都会完美地完成字符串,调试器不会显示任何不同的内容.