0

I am working on a legacy code, there is a class A which has an enum member defined like this

class A
{
private:
 enum E{ kRemove, kDoNotRemove};
 static map<String, MapValue> s_Map; //this map I am trying to add
}

I am trying to add a map in this class which will have structure as a value something like this

 struct MapValue{
      E e; //this enum is defined in private section in the class
      String T;
      String F;
  } ;

What I am unable to understand where should I define this struct MapValue?

My understanding:

  • If I add it inside the class Whenever I will create an object, a struct var will be allocated. This is not useful, as I am using this struct only as the value for the map. Also it is not the case that I need only one copy of this struct as I am using it as a value in the map.
  • If I add it outside the class, it will not be a good design as the struct is only inside the class, so it should not be global. Also the struct has enum member which is defined as private in the class, so it is not accessible outside the class.

Please suggest.

3
  • 2
    "If I add it inside the class Whenever I will create an object, a struct var will be allocated." Why do you think so? Commented Feb 13, 2019 at 12:50
  • it would help if you show some code demonstrating the first issue, because there is some misunderstanding... or maybe you are already happy with the given answer Commented Feb 13, 2019 at 12:51
  • @AlgirdasPreidžius sorry my understanding is incorrect and I am thankful for the answer provided Commented Feb 13, 2019 at 13:01

1 Answer 1

2

If you declare the type inside the class, it's just like the enum declaration, you are not allocating a new instance. This will only happen when an object is created int he map.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.