我對模板函式的函式指標感到困惑。
看
#include <cstdio>
class A
{
public:
A(){}
~A(){}
void command()
{
printf("Cmd");
}
};
template<class T>
void cmd_create()
{
T t;
t.command();
};
int main()
{
typedef void(*Funcptr)();
Funcptr f1 = &cmd_create<A>;
f1();
return 0;
}
程式輸出Cmd。
程式集 (-O3) 表明
.file "test.cpp"
.text
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "Cmd"
.section .text.startup,"ax",@progbits
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB38:
.cfi_startproc
leaq .LC0(%rip), %rsi
subq $8, %rsp
.cfi_def_cfa_offset 16
movl $1,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/457938.html
標籤:c class templates function-pointers
上一篇:如何優化getCommon方法?
