When declaring and defining a struct with a static member of the same type, i cannot seem to figure out how to define the value.
I have a struct containing two strings. I want there to be a defined/constant version I can access from the type itself. To do this I am declaring static members in a header and trying to define them in the class.
Header:
//.h
#pragma once
#include "BaseStruct.h"
#include<string>
namespace A {
namespace B{
struct MyStruct : A::C::BaseStruct
{
MyStruct(std::string s1, std::string s2);
static MyStruct myStaticStruct;
};
}
}
Class:
//.cpp
#include "BaseStruct.h"
#include "MyStruct.h"
namespace A {
namespace B {
struct MyStruct : A::C::BaseStruct
{
MyStruct(std::string s1, std::string s2) : BaseStruct(s1, s2)
{}
};
// I have been trying to define MyStaticStruct here.
}
}
How do I define the static member declared in the header? I can't access the static member using:
MyStruct::MyStaticStruct
but I have to use:
A::B::MyStruct::MyStaticStruct
Why can't I access the static member even though I am inside the A::B namespace? And of course, how do I define a value for that member?