This question already has an answer here:
I get a compilation error when trying to use the value return, look in the code below.
The error is: error: conversion from ‘boost::optional’ to non-scalar type ‘A’ requested
#include <boost/optional.hpp>
#include <iostream>
struct A
{
int x = 0;
int y = 0;
};
boost::optional<A> f_not_set()
{
boost::optional<A> result;
return result;
}
int main(int argc, char** argv)
{
auto a = f_not_set();
if(a)
{
A a1 = a; // <<<--- COMPILE ERROR
}
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire