Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ shared pointer operator bool

#include <iostream>
#include <memory>
 
void report(std::shared_ptr<int> ptr) {
    if (ptr) {
        std::cout << "*ptr=" << *ptr << "
";
    } else {
        std::cout << "ptr is not a valid pointer.
";
    }
}
 
int main() {
    std::shared_ptr<int> ptr;
    report(ptr);
 
    ptr = std::make_shared<int>(7);
    report(ptr);
}
//output:
//ptr is not a valid pointer.
//*ptr=7
Comment

PREVIOUS NEXT
Code Example
Cpp :: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ 
Cpp :: set to vector c++ 
Cpp :: check if cin got the wrong type 
Cpp :: summation of numbers using function 
Cpp :: cpp serial print override always in same place 
Cpp :: c++ include difference between quotes and brackets 
Cpp :: C++ file . 
Cpp :: pointer to value of others file cpp 
Cpp :: Write a C++ program to Computing Mean and Median Using Arrays 
Cpp :: why the << operator is friend 
Cpp :: 1822. Sign of the Product of an Array leetcode in c++ 
Cpp :: Bit Tricks for Competitive Programming c ++ 
Cpp :: find no of occurences of each letter in string c++ 
Cpp :: how to pronounce beaucoup 
Cpp :: apertura file in c++ 
Cpp :: how to seek to the start of afile in c++ 
Cpp :: How To Calculate 1+1 in c++ 
Cpp :: cout alternative c++ 
Cpp :: TCA9548 I2CScanner Arduino 
Cpp :: Password codechef solution in c++ 
Cpp :: How to execute a command and get return code stdout and stderr of command in C++ 
Cpp :: cin une énumération 
Cpp :: c++ hide credentials 
Cpp :: how to calculate 2^7 in cpp code 
Cpp :: free pair c++ 
Cpp :: c++ comments 
Cpp :: second smallest element using single loop 
Cpp :: qt unhandled exception handler 
Cpp :: Use command line arguments to create file c++ 
Cpp :: 130 divided by -10 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =