如何导入 std::less<T> 作为字体名?
How to import std::less<T> as a typename?
我在 Sol.h 中有以下代码,由于学校规则,大部分代码被省略了:
template <typename T,int promote = 1, typename compare = std::less<T>() >
class Sol{
private:
struct node{
T data;
struct node *next;
struct node *previous;
};
node *head, *tail;
public:
typedef unsigned int size_type;
typedef T key_type;
typedef T value_type;
size_type count;
Sol() : head(0), tail(0) {
count=0;
}
基本上它是一个类似于矢量的容器,但它做了一些我们需要模板的事情。我似乎无法获得"类型名称比较 = std::less
当我使用测试代码进行编译时,我从 Sol.h 收到两个错误,其余的都与它们有关。
>temple> g++ -Wall -Wextra -ansi -pedantic Sol.h main.cc
Sol.h:6:61: error: expected type-specifier
Sol.h:6:61: error: expected '>'
main.cc: In function 'int main()':
main.cc:19:19: error: template argument 3 is invalid
main.cc:19:24: error: invalid type in declaration before '(' token
main.cc:19:48: error: expression list treated as compound expression in initializer [-fpermissive]
main.cc:19:48: warning: left operand of comma operator has no effect [-Wunused-value]
main.cc:19:48: error: invalid conversion from 'char*' to 'int' [-fpermissive]
main.cc:20:19: error: template argument 3 is invalid
main.cc:20:31: error: expected initializer before 'it'
main.cc:22:13: error: request for member 'erase' in 'foo', which is of non-class type 'int'
main.cc:24:9: error: 'it' was not declared in this scope
main.cc:24:18: error: request for member 'find' in 'foo', which is of non-class type 'int'
main.cc:25:9: error: request for member 'end' in 'foo', which is of non-class type 'int'
main.cc:28:13: error: request for member 'find' in 'foo', which is of non-class type 'int'
main.cc:30:13: error: request for member 'find' in 'foo', which is of non-class type 'int'
main.cc: In function 'std::string cat(const T&) [with T = int, std::string = std::basic_string<char>]':
main.cc:23:24: instantiated from here
main.cc:12:35: error: 'int' is not a class, struct, or union type
main.cc:12:50: error: request for member 'end' in 'con', which is of non-class type 'const int'
main.cc:12:35: error: 'int' is not a class, struct, or union type
main.cc:12:35: error: 'int' is not a class, struct, or union type
main.cc:12:35: error: 'int' is not a class, struct, or union type
需要明确的是,第 6 行是模板行。
更改
typename compare = std::less<T>()
自
typename compare = std::less<T>
你想要一个类型,而不是一个对象。
你也必须做#include <functional>
因为这是定义std::less
的地方。
相关文章:
- 在C++中测量postscript字体宽度
- EASTL矢量<向量<int>>连续的
- 如何在Directwrite中获得给定字体的可用OpenType功能
- SetCurrentConsoleFontEx() 不适用于自定义安装的字体
- C++ wxWidgets:在创建小部件后设置字体
- C++ wxWidgets:更改大小器的字体
- C++ 位图中的 ttc 字体
- 从 QFontDatabase 设置 QFont 将所有标签设置为等宽字体?Qt C++
- 更改 Windows GUI 中静态文本框的字体大小
- SFML 中的字体.信息不显示在屏幕上.显示的不是信息,而是点
- 如何获取控制面板设置值,如字体大小
- ExtTextOut 文本的持续闪烁,在一段时间后,文本将恢复为默认字体
- 使用 TTF_RenderText() 加载字体时获取段错误 TTF_OpenFontRW()
- 通知 Windows 系统应用程序字体已被卸载/删除
- 使用 Visual Studio C++ 在控制台中控制字体和字符集
- OpenGL中使用Freetype进行字体渲染的问题不起作用
- CDialog 的标题/标题的字体样式
- 如何获取字体数据以嵌入到 PDF 中?
- 我可以存储字体名吗?
- 如何获取具有 Freetype2 的真正类型字体支持的代码点列表 C++