Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What are the use-cases of "complete-class context"? What's the benefit that a "complete-class context" provides?

In current working draft, the definition of complete-class context is: (§ 11.4.1 [class.mem.general]/7):

A complete-class context of a class (template) is a

  • (7.1) function body ([dcl.fct.def.general]),
  • (7.2) default argument ([dcl.fct.default]),
  • (7.3) default template argument ([temp.param]),
  • (7.4) noexcept-specifier ([except.spec]), or
  • (7.5) default member initializer

within the member-specification of the class or class template.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In fact, I don’t understand the intention of this wording. What are the use-cases of "complete-class context"? What’s the benefit that a "complete-class context" provides? So any further explanation will be appreciated.

For instance, what does mean that a function body is a complete-class context? Is this mean, for example, ..

struct X {
  void f(){
   X x{};
  }
};

.. that I can create an X object within the function body of X::f? if yes, does it mean anything else?

>Solution :

If we did not have a complete-class context then we could not write a class like

struct foo
{
    void bar() { std::cout << kitty; }
    std::string kitty = "meow";
};

because kitty isn’t known about until after bar is defined. You would have to write the class like

struct foo
{
    void bar();
    std::string kitty = "meow";
};

void foo::bar() { std::cout << kitty; }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading