“used without template parameters”

后端 未结 5 2038
慢半拍i
慢半拍i 2021-02-01 03:34

I realize similar questions have been asked before, but I read a couple of those and still don\'t see where I\'m going wrong. When I simply write my class without separating th

5条回答
  •  走了就别回头了
    2021-02-01 03:52

    VisitedSet is a template, not a class, so you can’t use VisitedSet in a nested name specifier such as VisitedSet::getSize(). Just as you specified the declaration of class VisitedSet for all class T, you must specify the definition of VisitedSet::getSize() for all class T:

    template
    int VisitedSet::getSize() {
    //            ^^^
        return vec.size();
    }
    

    The name of a template can, however, be used as though it were a class within a template definition:

    template
    struct Example {
        Example* parent;
        T x, y;
    };
    

    In this case, Example is short for Example.

提交回复
热议问题