   Need help
  Hi, The scenario://......................Class A{ protected: int num;};//......................#include "A.h"Class B : private A{};class A implements some API, and class B is a wrapper that simplify theuse of class A. I what to give the user an option to create only class B.Now is there a way to hide class A from the user ?(the user won't recognize class A, and won't be able to inherit from it).[ Class B must inherit from class A, friend releation is not an option, because  Class A should not recognize class B. ]tnx,   
PIMPL.// b.hppclass A; // forward declarationclass B {private:  A * pA;};Inheritance is not needed. If user doesn't have access to A, then the fact that B is A doesn't matter.PIMPL design above hides the implementation, so if A can be provided by a static library without code, or something similar. Actual instances of A are then created inside .cpp, for which the source doesn't need to be provided. a.hpp does not need to be included to use b.hpp.IMHO, there is little point in hiding code. All of this "must not extend" is not worth it, except in enterprise environments, and even then it's being abandoned since it causes more hassles than it saves.   ;  You can prevent class A from being inherited from by making it's constructors private. It should designate class B as a friend so B and only B can inherit from it.   ;  Well the solutions only answers on only one part of the question, but still there are problems:Antheus, indeed you hide A but, when you want to replace B, you have to implement A all over again. taz0010, the same problem, if you what to add D class, you need to add to A code another friend relation.( A code should be close, and don't care about others class ).Is there a ways of doing it at all? I can of think on ugly way ( throw constructor exception but hell it not nice ).;Quote:taz0010, the same problem, if you what to add D class, you need to add to A code another friend relation.( A code should be close, and don't care about others class ).You're trying to design a class that can only be inherited from by certain other class(es). By definition, this means your base class needs to know about the derived classes which are allowed to inherit from it. A base class which is independent of it's children does not care what inherits from it.   