c++ - 我的超类中带有结构定义的模板问题
问题描述
我有个问题。我的基类“ABC”有两个模板类 A 和 B。我的类“superABC”继承了 ABC,但第二个模板固定在字符串上。在 ABC 中有一个名为“structABC”的结构。在 superABC 中是一个从 structABC 返回实例的函数。当我尝试编写这个函数的实现时,编译器给了我
C2244 错误“无法将函数定义与现有声明匹配”。
有人可以告诉我问题是什么吗?
//ABC.h
#pragma once
template<class A, class B>
class ABC
{
public:
void func();
struct structABC {
};
structABC _referenceRange;
};
//superABC.h
#pragma once
#include "ABC.h"
#include "string.h"
template<class A>
class superABC:
public ABC<A, string>
{
public:
typename ABC<A, string>::structABC getBCD();
};
//superABC.cpp
#include "superABC.h"
template<class A>
inline typename ABC<A, string>::structABC superABC<A>::getBCD()
{
return ABC<A, string>::structABC();
}
解决方案
对我来说看起来像 MSVC 错误;原始代码使用 clang 编译。作为一种解决方法,添加一个 typedef for ABC<A, string>::structABC
,如下所示:
template<class A>
class superABC : public ABC<A, string>
{
using structABC = typename ABC<A, string>::structABC;
public:
structABC getBCD();
};
template<class A>
typename superABC<A>::structABC superABC<A>::getBCD()
{
return structABC();
}
推荐阅读
- javascript - 如何修复错误 GET http:... 404(未找到)
- regex - 如何按组和向后引用删除冒号(:)
- c# - 使用 LINQ 从列表中删除相同的元素
- java - android uid系统不兼容和系统签名
- ios - iOS libusrtcp.dylib 在 NWConcrete_nw_endpoint_flow updatePathWithHandler 上崩溃:
- graph-theory - 证明路径图论的存在
- onnx - 将yolov5模型转换为ONNX并在c++接口上运行
- java - 颤振android工作室(构建失败)
- c# - Column NameStudent 重复列 dataGrid 中数据库表的第一个元素
- vb.net - 如何使用 firebird 参数和条件进行查询