遇到 ''isSort()''declared here, later in the translation unit
在编写代码时,遇到
在原来的代码中出现这个问题

原来的代码:
//3 计算排序时间
template<typename T>
void testSort(string sortName, void(* sort) (T [],int ),T arr[],int n){
clock_t startTime = clock();
sort(arr,n);
clock_t endTime = clock();
assert(isSort(arr,n));
cout<<sortName<<":"<<double(endTime-startTime) / CLOCKS_PER_SEC<<"s"<<endl;
return;
}
// 4 判断是否是已排序的
template <typename T>
bool isSort(T arr[],int n){
for (int i = 0;i<n-1;i++){
if (arr[i] > arr[i+1]){
return false;
}
}
return true;
}
上面的代码死活不出来,但是两个调换顺序之后就可以了,详情见下面这个博客 ,但是博客中描述的是,在遇到普通函数时,需要把申明调用的函数先实例化,但模板函数不用,而这边本身就是模板函数,所以还是存在一点疑惑
prog.cpp: In instantiation of ‘void foo(T) [with T = int]’:
prog.cpp:16:7: required from here
prog.cpp:6:10: error: ‘bar’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
bar(x); // OKAY
^
prog.cpp:10:6: note: ‘template void bar(T)’ declared here, later in the translation unit
void bar(T x)
在gcc 4.8中看到的那样,它实际上并没有编译。编写 template 扩展器时,编译器在早期做的一件事就是将它们视为类似于宏的东西。当它们声明时,几乎不会做任何事情,而在实例化它们时,将查找所有内容。当 template 被声明,实例化时更少。
https://www.it1352.com/2094010.html
// 4 判断是否是已排序的
template <typename T>
bool isSort(T arr[],int n){
for (int i = 0;i<n-1;i++){
if (arr[i] > arr[i+1]){
return false;
}
}
return true;
}
//3 计算排序时间
template<typename T>
void testSort(string sortName, void(* sort) (T [],int ),T arr[],int n){
clock_t startTime = clock();
sort(arr,n);
clock_t endTime = clock();
assert(isSort(arr,n));
cout<<sortName<<":"<<double(endTime-startTime) / CLOCKS_PER_SEC<<"s"<<endl;
return;
}
遇到 ''isSort()''declared here, later in the translation unit的更多相关文章
- 低版本GCC程序向高版本移植的兼容性问题
将低版本gcc编译过的程序移植到高版本GCC时, 可能会出现一些兼容性问题. 原因是, 为了适应新的标准,一些旧的语法规则被废弃了. 关于这方面的一些具体资料可从该处查询. 这里只是自己遇到的其中一个 ...
- android 源码编译中的错误 解决
1.编译种错误提示: arm-none-linux-gnueabi-gcc: directory: No such file or directory arm-none-linux-gnueabi-g ...
- android 源码编译 问题 列表
转自:http://www.cnblogs.com/xilinch/archive/2013/04/02/2996359.html make: *** [out/host/linux-x86/obj/ ...
- linux mint 17编译android 2.3.1错误记录
有转载这里的也有添加的. ################# Fix 1 ########################## Error: frameworks/base/include/utils ...
- Android 安全攻防(一):SEAndroid的编译
转自:http://blog.csdn.net/yiyaaixuexi/article/details/8330645 SEAndroid概述 SEAndroid(Security-Enhance ...
- Phases of translation
Phases of translation--翻译阶段 The C++ source file is processed by the compiler as if the following pha ...
- C++ essentials 之 static 关键字
extraction from The C++ Programming Language, 4th. edition, Bjarne Stroustrup If no initializer is s ...
- iOS:消除项目中警告
引言: 在iOS开发过程中, 我们可能会碰到一些系统方法弃用, weak.循环引用.不能执行之类的警告. 有代码洁癖的孩子们很想消除他们, 今天就让我们来一次Fuck 警告!! 首先学会基本的语句: ...
- 5.24 Declaring Attributes of Functions【转】
转自:https://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html 5.24 Declaring Attributes o ...
随机推荐
- 想买保时捷的运维李先生学Java性能之 运行时数据区域
前言 不知道自己不知道,不知道自己知道,知道自己不知道,知道自己知道,目前处于知道自己不知道这个阶段,很痛苦啊,干了4年了运维,是一个坎.越来越发觉想要走得远,还是得扎根底. 一.运行时数据区域 ...
- 记一次flink入门学习笔记
团队有几个系统数据量偏大,且每天以几万条的数量累增.有一个系统每天需要定时读取数据库,并进行相关的业务逻辑计算,从而获取最新的用户信息,定时任务的整个耗时需要4小时左右.由于定时任务是夜晚执行,目前看 ...
- ps基本工具
2.1PS移动工具 (1)快捷键:V. (2)多对象跨窗口移动的时候,按住键盘的shift再按鼠标左键拖拽可以快速定位到中心位置. (3)图层,一层层透明纸张叠加到一块的显示效果,每张透明的纸张上都有 ...
- Lock接口示例
Lock 的挂起 await() 唤醒signal() Lock 简单示例 public class LockDemo { public static void main(String[] args ...
- Paillier同态加密的介绍以及c++实现
我们先来简短认识一下Paillier同态加密算法: 如果就这么按照定义来用最简朴的c++程序写 就像这样: #include <iostream> #include <math.h& ...
- pwn之栈缓冲区溢出漏洞(入门)
题目ret2text 题目信息确认 使用file命令查看文件类型 root@CTF:/home/# file ret2text ret2text: ELF 32-bit LSB executable, ...
- ThreadLocal使用说明
让变量只能在这个线程内被读写,在其他线程内无法被访问.以键值对存放变量,并继承弱应用,内存随时会被回收,用完要remove不然会内存泄漏,使用的时候直接设置值就可以了,键就是ThreadLocal本身 ...
- c#封装ActiveX接口实践分析
ActiveX接口 是一个开放的集成平台,为开发人员.用户和 Web生产商提供了一个快速而简便的在 Internet 和 Intranet 创建程序集成和内容的方法. 使用 ActiveX, 可轻松方 ...
- C语言之 Switch和?:运算符的反汇编
Switch条件语句 通过上面一篇了解了条件语句的使用,接下来就直接进行反汇编学习 #include <stdio.h> void print() { int b = 1; switch ...
- C# 中的只读结构体(readonly struct)
翻译自 John Demetriou 2018年4月8日 的文章 <C# 7.2 – Let's Talk About Readonly Structs>[1] 在本文中,我们来聊一聊从 ...