在编写代码时,遇到

在原来的代码中出现这个问题



原来的代码:

//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的更多相关文章

  1. 低版本GCC程序向高版本移植的兼容性问题

    将低版本gcc编译过的程序移植到高版本GCC时, 可能会出现一些兼容性问题. 原因是, 为了适应新的标准,一些旧的语法规则被废弃了. 关于这方面的一些具体资料可从该处查询. 这里只是自己遇到的其中一个 ...

  2. android 源码编译中的错误 解决

    1.编译种错误提示: arm-none-linux-gnueabi-gcc: directory: No such file or directory arm-none-linux-gnueabi-g ...

  3. android 源码编译 问题 列表

    转自:http://www.cnblogs.com/xilinch/archive/2013/04/02/2996359.html make: *** [out/host/linux-x86/obj/ ...

  4. linux mint 17编译android 2.3.1错误记录

    有转载这里的也有添加的. ################# Fix 1 ########################## Error: frameworks/base/include/utils ...

  5. Android 安全攻防(一):SEAndroid的编译

    转自:http://blog.csdn.net/yiyaaixuexi/article/details/8330645 SEAndroid概述   SEAndroid(Security-Enhance ...

  6. Phases of translation

    Phases of translation--翻译阶段 The C++ source file is processed by the compiler as if the following pha ...

  7. C++ essentials 之 static 关键字

    extraction from The C++ Programming Language, 4th. edition, Bjarne Stroustrup If no initializer is s ...

  8. iOS:消除项目中警告

    引言: 在iOS开发过程中, 我们可能会碰到一些系统方法弃用, weak.循环引用.不能执行之类的警告. 有代码洁癖的孩子们很想消除他们, 今天就让我们来一次Fuck 警告!! 首先学会基本的语句: ...

  9. 5.24 Declaring Attributes of Functions【转】

    转自:https://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html 5.24 Declaring Attributes o ...

随机推荐

  1. postgresql使用规范解读

    表设计规范1.建议能使用小字节数类型,就不要用大字节数类型2.建议能用varchar(N).text就不用char(N):3.建议使用default NULL,而不用default '':4.建议使用 ...

  2. vant学习网址

    https://youzan.github.io/vant/#/zh-CN/swipe-cell 我推荐大家可以在这个网址上面学习vant相关的知识   里面有代码解说和详细的代码

  3. SSM中 spring-mvc.xml 配置文件

    <!--扫描控制器包--><context:component-scan base-package="<!--控制器包所在路径-->">< ...

  4. Rest Framework设计规范

    Rest Framework Rest Framework是前后端分离中用到的一种规范,它与框架本身无关,是一种软件架构风格,全称为Representational State Transfer. R ...

  5. 痞子衡嵌入式:基于恩智浦i.MXRT1010的MP3音乐播放器(RT-Mp3Player)设计

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是基于i.MXRT1011的MP3播放器参考设计. i.MXRT1011是恩智浦i.MXRT四位数系列的入门型号,虽然是入门级,可也是50 ...

  6. robotframework执行UI自动化时不能运行谷歌浏览器的问题

    robotframework执行UI自动化时报错,查看日志显示Parent suite setup failed: Variable '${browser}' not found. Did you m ...

  7. 【总结】vertica数据库

    1.简介 Vertica是一款基于列式存储架构的数据库,可以支持存放多至PB级别的结构化数据 2.列式存储 行式存储就是以行为单位进行存储,再配合B+树作为索引,就能快速通过主键找到相应的行数据.即大 ...

  8. 走在深夜的小码农 Sixth Day

    Css3 Six Day writer:late at night codepeasant 学习大纲: 一.其他样式 1.圆角边框 在 CSS3 中,新增了圆角边框样式,这样我们的盒子就可以变圆角了. ...

  9. 从原生web组件到框架组件源码(一)

    温馨提醒,当你觉得看我写的很乱的时候,就对了,那是因为我查阅了大量的资料提取出来的,因为有点东西不太理解,所以你会感觉有的部分重复了,也不是重复,只是后面对前面的内容进行梳理了一些,需要耐心的看到最后 ...

  10. STM32入门系列-库目录及文件介绍

    已经介绍了过了CMSIS标准,ST公司按照这个标准设计了一套基于STM32F10x的固件库,我们可以直接在ST公司的官网进行下载,现在给大家STM32最新固件库v3.5,在网盘上给大家提供了下载包,链 ...