在编写代码时,遇到

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



原来的代码:

//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. js和vue方法的相互调用(iframe父子页面的方法相互调用)。

    项目是前后端不分离的,模板引擎使用的JSP. 但是使用了Vue+ElementUI,这里列举一些常用的调用方式,有时候可能. 在js里调用vue方法 我们需要把方法注册到vue对象之外的页面,所以对与 ...

  2. JavaWeb中的域对象

    域对象:可以在不同Servlet之间传递数据的对象,就是域对象,它们内置了map集合,都有setAttribute和getAttribute方法: Java Web有ServletContext.Se ...

  3. frida框架hook获取方法输出参数(常用于简单的so输出参数获取,快速开发)

    一.模板 function douyinencode(data) { var result = {}; Java.perform(function () { try { var Test = Java ...

  4. IDEA Cannot resolve plugin org.apache.maven.plugins:maven-site-plugin:3.8.2-plugin爆红错误

    如果确认本地库存在,maven仓库配置正确,将其显式声明出来,问题解决 <!--报找不到该依赖的错误, 本地库又存在,将其显式声明在这里,问题解决--> <plugin> &l ...

  5. APP打开(三)—激活率提升20%的思考

    激活是APP拉新后的一个重要环节.通常,我们希望用户打开我们的APP之后,能够顺利的被激活,从而留下来成为我们的忠实用户. 激活一词,就跟北斗星指标一样,对每个产品来说都是不一样的.有些APP一旦打开 ...

  6. service下载任务

    在service开启线程,利用接口更新进度 public class MainActivity extends AppCompatActivity { MyBindService msgService ...

  7. Phoenix创建索引源码过程

    date: 2020-09-27 13:50:00 updated: 2020-09-28 16:30:00 Phoenix创建索引源码过程 org.apache.phoenix.index.Inde ...

  8. sqlServer数据库中的日期转换

    今天开发过程中涉及到 sqlServer数据库数据同步至mysql数据,所以对日期格式转换需求,查到了一些关于sqlServer 的日期转换内容: 一般存入数据库中的时间格式为yyyy-mm-ddhh ...

  9. 01 . Go框架之Gin框架从入门到熟悉(路由和上传文件)

    Gin框架简介 Gin是使用Go/Golang语言实现的HTTP Web框架, 接口简洁, 性能极高,截止1.4.0版本,包含测试代码,仅14K, 其中测试代码9K, 也就是说测试源码仅5k左右, 具 ...

  10. 蒲公英 · JELLY技术周刊 Vol.28: Next.js 10 发布

    蒲公英 · JELLY技术周刊 Vol.28 前端应用到底该选 SSR 还是 CSR?每个项目技术栈决策的时候都会根据实际需求有自己的看法,而在不久前 React 17 发布之后,自然而然也会有同学好 ...