vendredi 10 avril 2020

C++,Shared_ptr, Please tell me why blow code is giving error?

getting error- 1>E:\VS\HelloWorld\HelloWorld\main.cpp(14,10): error C2679: binary '=': no operator found which takes a right-hand operand of type 'int *' (or there is no acceptable conversion) 1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\memory(1143,17): message : could be 'std::shared_ptr &std::shared_ptr::operator =(std::shared_ptr &&) noexcept' 1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\memory(1132,17): message : or 'std::shared_ptr &std::shared_ptr::operator =(const std::shared_ptr &) noexcept' 1>E:\VS\HelloWorld\HelloWorld\main.cpp(14,10): message : while trying to match the argument list '(std::shared_ptr, int *)' 1>Done building project "HelloWorld.vcxproj" -- FAILED.

#include <iostream>
#include <vector>
#include <algorithm>
#include<string>
#include  <memory>

using namespace std;

int main()
{
    shared_ptr<int> ptr = make_shared<int>();
    int l = 10;
    ptr = &l;
    cout << (*ptr) << endl;

    cin.get();
}

Aucun commentaire:

Enregistrer un commentaire