c++ - 我怎样才能摆脱出现在我的方法模板中的类型?方法和类的输入都是模板
问题描述
我收到错误
declaration is incompatible with "void spectrogram<T>::update(<error-type> x)
我看不出方法的声明和定义之间有任何区别,不知道为什么它只抱怨这个定义而不是构造函数或析构函数。
这是 vComplex.hpp
#ifndef VCOMPLEX_H
#define VCOMPLEX_H
template <class T>
class vComplex {
public:
T* realp;
T* imagp;
int length; // for bookkeeping
vComplex(void) { }
vComplex (T* I, T* Q, int len) {
realp = I;
imagp = Q;
length = len;
}
~vComplex(void) {
free(realp);
free(imagp);
}
void put(T* I, T*Q, int len) {
realp = I;
imagp = Q;
length = len;
}
};
#endif
spectrogram.hpp 中更新的函数声明,删除了其他成员:
#ifndef SPECTROGRAM_H
#define SPECTROGRAM_H
template <typename T>
class spectrogram {
public:
void update(vComplex<T> x);
};
#endif
以及用于更新 spectrogram.cpp 的函数签名(和包含):
#include <stdio.h>
#include <math.h>
#include "spectrogram.hpp"
#include "vComplex.hpp"
template <typename T>
void spectrogram<T>::update(vComplex<T> x) {
//do stuff
}
在 VS 2017 中,我在更新下得到了红色下划线,其中的所有内容基本上都坏了。VS 说 T 是未定义的,我假设这是由整体错误引起的。我必须使用动态分配的指针,我没有使用其他类型或容器的选项。
解决方案
推荐阅读
- c++ - 用于迭代多个集合的数据结构
- javascript - 动态设置全局 JS 变量
- javascript - 访问 Map 时超出 Javascript 最大调用堆栈大小错误
- php - 如何在考试中获得学生排名
- php - 如何:将 Laravel 集合折叠成逗号分隔的字符串?
- swift - 使用 swift 调用 webAPI
- android - 反应本机文本输入比较。不适用于 Android 中的特定位置
- python - 我应该在哪里放置单元测试的辅助函数?
- c++ - 我在 C++ 中收到的每个错误都有 4 个相同的无用错误
- kotlin - 具有可变数量的类型化参数和具有相同数量类型化参数的闭包的函数?