You can't use the C++-style approach in C#.
I've encountered this before, and I usually solve it by making the class A abstract
(requires inheritance) and the constructor protected
(only classes inheriting from the class can call the constructor).
I then create a private
class within class B (called something like '_A') and inherit from A. (There's no additional code within _A.) _A defines a constructor which is public - thus visible to B (and B only, since _A is private).
Within B, you can create instances of _A and return them as A (via polymorphism).
I prefer this approach to the public interface because my class B code file ends up huge if class A is implemented within it. That's just my preference though - others may have different opinions.
abstract class A
{
protected A()
{
}
/* implementation details... */
}
public class B
{
public A GetInstance()
{
return new _A();
}
private class _A : A
{
public _A()
{
}
}
}