在编写代码时,遇到

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



原来的代码:

//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. windows10下IntelliJ IDEA使用logback设置日志输出目录

    1.在项目的src/main/resources目录下新建文件:logback-spring.xml 2:在logback-spring.xml中进行如下配置: <?xml version=&q ...

  2. Kubernetes K8S之调度器kube-scheduler详解

    Kubernetes K8S之调度器kube-scheduler概述与详解 kube-scheduler调度概述 在 Kubernetes 中,调度是指将 Pod 放置到合适的 Node 节点上,然后 ...

  3. 安卓WebSocket使用

    引入jar包: implementation "org.java-websocket:Java-WebSocket:1.4.0"implementation "org.s ...

  4. WTM系列教学视频全免费

    WTM框架问世以来,受到越来越多开发者的喜爱,为了回报大家的厚爱,原本在CSDN上的教学视频已经全部免费,900多分钟的视频,而且还会继续更新. 为了方便大家观看,在B站上也同步更新,地址如下: CS ...

  5. Java安全之Commons Collections5分析

    Java安全之Commons Collections5分析 文章首发:Java安全之Commons Collections5分析 0x00 前言 在后面的几条CC链中,如果和前面的链构造都是基本一样的 ...

  6. .net npoi读word内容+目录

    最近在做读npoi文档存入搜索引擎,实现快速查询word文档中内容并展示,效果希望带有目录导航. 网上有很多例子都是读写操作,很肤浅没有具体读到想要的东西所以自己就写了个demo,也有微软提供的off ...

  7. 【转载】HPL与HPCG测试(一)

    来源:HPL与HPCG测试 (一) 一.HPL与HPCG 简介 1.HPL HPL 即 High Performance Linpack,它是针对现代并行计算集群的测试工具.用户不修改测试程序,通过调 ...

  8. 串口服务器和modbus网关有什么不同

    串口服务器是什么? 串口服务器一般也会被称之为串口设备服务器,它是一种小型电子设备,可以将以太网IP/TCP数据包转换为RS232,RS485或RS422串口数据信号,反之亦然. Modbus网关是什 ...

  9. JS+CSS+HTML实现“代码雨”类似黑客帝国文字下落效果

    HTML代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <l ...

  10. Jmeter-全局变量跨线程组使用

    一.前言 前面讲了如何使用正则表达式提取值,一般提取的值在同一个线程里,随意哪个请求都是可以引用的,那如果别的线程组也想引用怎么办呢?这时就涉及到一个全局变量的知识点了,话不多说,直接实例走起. 二. ...