expected
#include <iostream>
#include <optional>
using namespace std;
int main() {
optional<int> number = 10;
if (number.has_value()) {
cout << "The value of the number is: " << *number << endl;
} else {
cout << "The number is not set" << endl;
}
return 0;
}#include <iostream>
using namespace std;
class MyClass {
public:
MyClass() : ptr(nullptr) {}
void setPtr(int* ptr) { this->ptr = ptr; }
int* getPtr() { return ptr; }
private:
int* ptr;
};
int main() {
MyClass myClass;
if (myClass.getPtr() != nullptr) {
cout << "The pointer is not null" << endl;
} else {
cout << "The pointer is null" << endl;
}
return 0;
}