遇到 ''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 ...
随机推荐
- php7.1安装openssl扩展
1,进入到PHP源码目录中的ext中的openssl目录 2,phpize 3,./configure --with-openssl --with-php-config=/usr/local/php/ ...
- Go的第一个Hello程序 简简单单 - 快快乐乐
Go的第一个Hello程序 简简单单 - 快快乐乐 JERRY_Z. ~ 2020 / 10 / 29 转载请注明出处!️ 目录 Go的第一个Hello程序 简简单单 - 快快乐乐 一.Go程序开发基 ...
- Java 运行时动态生成class
转载 http://www.liaoxuefeng.com/article/0014617596492474eea2227bf04477e83e6d094683e0536000 Java是一门静态语言 ...
- 学习写简单的RPC框架demo
学习实现一个简单的RPC框架. 工程主要目录分级结构: rpc-common: 公共基础包,能力提供包 rpc-provider: 服务提供者 rpc-consumer:服务消费者 rpc-servi ...
- 快来,我悄悄的给你说几个HashCode的破事。
这是why技术的第 72 篇原创文章 Hash冲突是怎么回事 在这个文章正式开始之前,先几句话把这个问题说清楚了:我们常说的 Hash 冲突到底是怎么回事? 直接上个图片: 你说你看到这个图片的时候想 ...
- 工业级4G路由器有哪些优势
在金融.电力.邮政以及气象等各大行业中有着更为广泛的应用,并受到人们的高度推崇与青睐,那么工业级4G路由器有哪些优势深受用户的喜欢呢? 1.高稳定性 工业级4G路由器在传输和接收数据时具有较高的稳定性 ...
- Redis常用命令(2)——String
APPEND 格式:APPEND key value 作用:在key的键值后追加value,如果key不存在,则创建key,并存入value. 返回值:追加value后的字符串长度. 示例: 192. ...
- ci框架根据配置自动生成controller控制器和model控制器(改版本)
CI修改如下: if($modle_file=config_item('modle_file')) { if ($modle_file === TRUE) { $modle_file=config_i ...
- .NET EF实现NoLock
sql实现方法: select * from 表名(nolock) 加上(nolock) EF实现办法: 程序集引用 System.Transactions ...
- IL角度理解for 与foreach的区别——迭代器模式
IL角度理解for 与foreach的区别--迭代器模式 目录 IL角度理解for 与foreach的区别--迭代器模式 1 最常用的设计模式 1.1 背景 1.2 摘要 2 遍历元素 3 删除元素 ...