Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
Source by en.cppreference.com #
 
PREVIOUS NEXT
Tagged: #shared #pointer #operator #bool
ADD COMMENT
Topic
Name
7+9 =