Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a class named Symbol and I would like to create a QVector subclass (Symbols) to add some useful methods. But when I use Symbols from another class A, the compiler gives the error 'Symbols does not name a type'.

class Symbols: public QVector< Symbol >
{
public:
    Symbols() {}

    // Useful methods
    QSymbol findSymbol(const QString &name);

    // ...
};

class A
{
private:
    Symbols symbols;
};

Is it correctly subclassed?

Why appears 'Symbols does not name a type' when compiles class A?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
188 views
Welcome To Ask or Share your Answers For Others

1 Answer

It's usually ill advised to derive from a container. You almost always want a "Has A" relationship otherwise your class will expose members that users of your class can use which may corrupt the state.

Also it looks like you're trying to implement a look up in your class which means perhaps QMap or QHash would be a more appropriate container


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...