문제

I am in the process of refactoring a framework, and I could use some advise for design. Consider the following:

gl_utils.lib contains the struct:

namespace gl_utils
{
    struct LVec2
    {
        GLfloat x;
        GLfloat y;
        LVec2() {}
        LVec2(GLfloat x, GLfloat y): x(x), y(y) {}
    };
}

however animation_utils.lib contains an object using a struct in a different static library:

#include "gl_utils.h"
using namespace gl_utils;

class Part
{
    public:
        LVec2 Location;
        float Rotation;
        LVec2 Scaling;
        int Index;
        int Flip;

        Part();
};

Is this a bad idea? Is there a safe way to have libraries build on each other, or is there a technique that I am overlooking?

도움이 되었습니까?

해결책

It is perfectly fine. You have to document it however since final executable or shared library will need to link with both static libraries.

If you don't want to introduce a dependency on gl_utils for animation_utils, you could introduce a core library for example to hold the LVec2(and possibly other types) struct as it is not exclusively gl related.

You'll still need to link on core library though but it could make the architecture even more modular.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top