简体   繁体   English

从模板化 function 调用非模板化 function

[英]Calling a non templated function from a templated function

Hy.海。 My question is that, I have a templated function in ah file and inside i want to call a function which was not implemented any templates, it's just a basic "declaration and definiton" func.我的问题是,我在 ah 文件中有一个模板化的 function,在里面我想调用一个没有实现任何模板的 function,它只是一个基本的“声明和定义”功能。 It's possible to call a non-templated function from a templated one?可以从模板调用非模板 function 吗?

.h file .h 文件

template <typename T>
void func(T &param){

   //do something...

   int p=func2(some param);
}

.cpp file .cpp 文件

int func2(some param){
   int a;

   //do something..

   return a;
}

I got an error code: there are no arguments to 'func2' that depend on a template parameter, so a declaration of 'func2' must be available我收到一个错误代码:没有 arguments 到 'func2' 依赖于模板参数,因此必须有一个 'func2' 的声明

After hours of googling i found the answer: In my.h file the经过数小时的谷歌搜索,我找到了答案:在 my.h 文件中

int func2(some param)

was declared after than the templated funcion.在模板化函数之后声明。 So the compiler did not see it.所以编译器没有看到它。 So correctly it looks like this:所以正确地看起来像这样:

int func2(some param);


template <typename T>
 void func(T &param){

   //do something...

   int p=func2(some param);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM