Category : access-specifier

Recently, I came across code like this: class NeedsFactoryForPublicCreation { private: struct Accessor { // Enable in order to make the compile failing (expected behavior) // explicit Accessor() = default; }; public: explicit NeedsFactoryForPublicCreation(Accessor) {} // This was intended to be the only public construction way static NeedsFactoryForPublicCreation create() { NeedsFactoryForPublicCreation result{Accessor()}; // … Do ..

Read more

I am compiling a class, the complete program to which is given below: #include<iostream> using namespace std; class Test{ public: Test() { cout<<"Test variable created…n"; // accessing width variable in constructor cout<<"Width is "<<width<<".n"; } void setHeight(int h) { height = h; } void printHeight() { cout<<"Height is "<<height<<" meters.n"; } int width = 6; ..

Read more

While trying to get some old software to compile with clang, I encountered some code similar to the following: class OuterClass { private: template <class T> class InnerClass {}; }; template <class T> class OtherClass {}; template <class T> class OtherClass<OuterClass::InnerClass<T>> {}; My understanding of this code is that the template class OtherClass is specialized ..

Read more

While trying to get some old software to compile with clang, I encountered some code similar to the following: class OuterClass { private: template <class T> class InnerClass {}; }; template <class T> class OtherClass {}; template <class T> class OtherClass<OuterClass::InnerClass<T>> {}; My understanding of this code is that the template class OtherClass is specialized ..

Read more