error: there are no arguments to ‘size‘ that depend on a template parameter, so a declaration of ‘si

完整的错误:

error: there are no arguments to ‘size’ that depend on a template
parameter, so a declaration of ‘size’ must be available [-fpermissive]
T pop() { return remove ( size() - 1 ); }

这是在使用之前编译通过的Vector模板类后,新建栈类 Stack 对Vecor公有继承。

然而,在Stack中使用Vector的public成员和protected成员却出现了这样的错误。
错误信息表明,缺少了对size()函数的声明。实际上size()函数声明和实现在自定义vector.h中,这里已经#include"vector.h",却出错了???

当前的编译器是 MinGW的。

换成VS 的MSVC编译器后就没有错误,正常运行。

百思不得其解。明明有声明和包含,为什么在MinGW工具下会编译出错呢??

找到一条相关的说明:
linux编译中error: no arguments depend on a template parameter, declaration of * must 解决_Lyndon的专栏-CSDN博客_error: there are no arguments to glgenrenderbuffe https://blog.csdn.net/donglynn/article/details/21807583?utm_source=blogxgwz4

error: there are no arguments to ‘size‘ that depend on a template parameter, so a declaration of ‘si

所以,上述错误的原因在于。gcc编译器取消了头文件的多层关联。之前的版本中,main.cpp中包含了vector.h,编译器可以从当前文件main.cpp中包含的头文件vector.h多层的链接到vector.h中包含的头文件(我的实现中,是将vector.h中的方法实现在其他头文件中,再在vector.h中包含这些头文件)。
但现在,多层链接功能失去了,所以size()成了来路不明的函数。并且这里的Stack的push方法调用的Vector的push_back即使添加声明也会失效,因为声明是在vector.h,但实现却在其他的头文件中。