Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 解释C++;指针初始化_C++ - Fatal编程技术网

C++ 解释C++;指针初始化

C++ 解释C++;指针初始化,c++,C++,而不是 int *pValue2(pValue1); 但它仍在发挥作用,并产生了适当的结果。 有人能告诉我在这种情况下调用了哪个默认函数或构造函数吗 int *pValue2 = new int; pValue2 = pValue1; 相当于 int *pValue2(pValue1); 只需分配给pValue2pValue1(分配给pValue2变量的地址value)。除了指针引用的值之外,如果您打印指针本身(地址),差异应该是明显的: int* pValue2 = pValue1;

而不是

int *pValue2(pValue1); 
但它仍在发挥作用,并产生了适当的结果。 有人能告诉我在这种情况下调用了哪个默认函数或构造函数吗

int *pValue2 = new int;
pValue2 = pValue1;
相当于

int *pValue2(pValue1);

只需分配给
pValue2
pValue1
(分配给
pValue2
变量的地址
value
)。

除了指针引用的值之外,如果您打印指针本身(地址),差异应该是明显的:

int* pValue2 = pValue1;
#包括
使用名称空间std;
int main(){
int值=3;
int*pValue1=&value;
int*pValue2(pValue1);
int*pValue3=新的int;

为什么这个标签是<代码> C++ 11 和<代码> C++ 14 < /C>?还是在工作-你的另一个方法不起作用,它泄露内存。你分配新的内存,然后立即把它指向一个点,因为我在Visual Studio 2013上工作。我不知道它是否与C++ 11或C++有关。14@Nihar你可以看到c+11oR C++ 14作为C+-C++语言的“升级”。因为你不使用“特殊”函数,比如lambdas,它将依赖于用法到C++ 11/C++ 14,你的问题只需要用C++来标记。
int* pValue2 = pValue1;
#include <iostream>
using namespace std;

int main() {
    int value = 3;
    int *pValue1 = &value;
    int *pValue2(pValue1);
    int *pValue3 = new int;
    cout << pValue1 << " " << pValue2 << " " << pValue3 << endl;
    cout << *pValue1 << " " << *pValue2 << " " << *pValue3 << endl;

    pValue3 = pValue1;
    cout << pValue1 << " " << pValue2 << " " << pValue3 << endl;
    cout << *pValue1 << " " << *pValue2 << " " << *pValue3 << endl;

    return 0;
}