0

I have got a branched datstructure, which is mainly build out of structs and Integers. Some Elements are signed with the std::optional template. In the case of an optional struct element, in another struct, which itself is also referenced in another struct as optional, I get the Error:

Error (active) E0135 class "BasicContent" has no member "km"

That's the code producing this error:

#include "stdafx.h"
#include <optional>


using IntType = int;

struct BasicContent {
    IntType Speed;
    std::optional<IntType> km;
};

struct Message {
    std::optional<BasicContent> basicContent;
};

int main()
{
    Message myMessage;
    myMessage.basicContent->km = 5;

    return 0;
}

The weird thing is, that I can run the code and write to all the data, but it keeps showing this error. Also in the watch "km" is shown as nullopt, but in everything is fine. Is there a solution for this or is there something I don't see?

Gabriel
  • 11
  • 5

0 Answers0