遇到 ''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 ...
随机推荐
- 看完这篇良心帖!你的Python入门基础就差不多了
有段时间没跟各位粉丝分享编程资源福利了,看了下自己的资料夹,就剩下我认为比较好的Python学习资料了.相信这套资料可以对你进阶高级工程师有帮助!全民学Python的话题铺天盖地,中国的Python学 ...
- node.js操作MySQL数据库
MySQL数据库作为最流行的开源数据库.基本上是每个web开发者必须要掌握的数据库程序之一了. 基本使用 node.js上,最受欢迎的mysql包就是mysql模块. npm install mysq ...
- Ngnix01
Nginx(一)------简介与安装 目录 1.Nginx 的简介 2.Nginx 的常用功能 3.Nginx 安装 ①.下载地址 ②.Windows 版本安装 ③.Linux 版本安装 说到 ...
- Camera2使用surface支持
surfaceview是运行在子线程,可以为相机提供不断的刷新 public class MainActivity extends AppCompatActivity { public void on ...
- 深度学习中卷积层和pooling层的输出计算公式(转)
原文链接:https://blog.csdn.net/yepeng_xinxian/article/details/82380707 1.卷积层的输出计算公式class torch.nn.Conv2d ...
- IDEA操作git的一些常用技巧
转自:https://blog.csdn.net/ck4438707/article/details/53455962 Git原理以后会分章节介绍,本次主要说一下intellij怎样操作git.int ...
- RocketMQ4.7.1双主双从集群搭建
导读 上一集我们已经学会了SpringBoot整合RocketMQ点我直达,今天我们来搭建双主双从高性能MQ服务集群. 简介 主从架构 Broker角色,Master提供读写,Slave只支持读,Co ...
- 使用Azure静态Web应用部署Blazor Webassembly应用
上一次演示了如何使用Azure静态web应用部署VUE前端项目(使用 Azure静态web应用+Github全自动部署VUE站点).我们知道静态web应用支持VUE,react,angular等项目的 ...
- vue父组件促发子组件中的方法
实现在父组件中促发子组件里面的方法 子组件: <template> <div> 我是子组件 </div> </template> <script& ...
- 写文档太麻烦,试试这款 IDEA 插件吧!
前言 每次开发完新项目或者新接口功能等,第一件事就是提供接口文档.说到接口文档,当然是用 Markdown 了.各种复制粘贴字段,必填非必填,字段备注,请求返回示例等等.简直是浪费时间哇.所以想到了开 ...