C++ How can I hide a public class? -


i'm coding game engine , i'm creating resource base classes such vertexes, textures, fonts, etc.

now i'm creating basic classes want exposed programmer uses these base classes, such image (uses textures), text (uses fonts), models (uses vertexes) etc

the game engine exposed, can call it's functions , such coding game.

but don't want them access base classes @ all, , don't want conflict classes well. example, might want create class named "material" ingame resources have "material" class, how can avoid conflict , better, hide these base classes (so don't mess , break something)?

edit: example, have exposed class image. contains private instances of quad , texture base classes, , resource manager makes sure there's 1 of these loaded (so don't have duplicate textures/quads in memory).

texture has width/height, , manages data loaded card. same quad.

image makes sure when image resize requested, changes needs changed , reuploads data card.

texture , quad public because they're used everywhere, there's modules , classes apply effects it.

they (other programmers) can use image instances, inheritance, or members, since manages itself, , want image class exposed, don't ever know there's quad , texture classes , doesn't interfere class naming well.

the first (and easiest) method enclose objects in library in specific namespace.

then gets bit more complicated. if exporting "public classes" make use of "internal classes" via containment, can using forward declarations, , keeping pointers "private classes" use. can done behaviors , attributes using pimpl idiom

here's example:

namespace foo {    class barimpl;     class bar    {    // ...    private:       std::unique_ptr<barimpl> object_;    }; } 

however, if "public classes" require definition of "private classes" (either through direct containment, or inheritance) there isn't way provide library (in source form) users without providing "easy" access supporting classes.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -