所有代码都应该做的是创建类的一个实例并打印私有变量。我查看了该站点上的一堆(超过 20 个)“错误 C4430:缺少类型说明符”错误,但没有任何帮助。
这是类文件(“Number.h”):
#ifndef NUMBER_H
#define NUMBER_H
#include <string>
template <typename T>
class Number {
private:
T myVar;
public:
Number(T consVariable);
~Number();
void setNumber(T newVar);
T getNumber();
bool isEqual(T check);
bool isBigger(T check);
bool isSmaller(T check);
};
template <typename T>
Number<T>::Number(T conVar) {
myVar = conVar;
}
template <typename T>
Number<T>::setNumber(T setVar) {
myVar = setVar;
}
template <typename T>
Number<T>::getNumber() {
return myVar;
}
template <typename T>
Number<T>::isEqual(T n) {
if (myVar == n)
return true;
else
return false;
}
template <typename T>
Number<T>::isBigger(T n)
{
if (myVar >= n)
return true;
else
return false;
}
template <typename T>
Number<T>::isSmaller(T n)
{
if (myVar <= n)
return true;
else
return false;
}
#endif
和错误:
number.h(31): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
number.h(36): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
number.h(44): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
number.h(53): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
number.h(62): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int