小编Vol*_*nko的帖子

候选模板被忽略:无法将“const type-parameter-0-0 *”与“char”匹配

我想制作自己的库,但模板函数有一些问题。

主程序

#include <iostream>
#include "SMKLibrary.h"

int main() {
    char a[5] = {"ASFD"};

    array_print(a,5);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

SMKLibrary.h

#ifndef SMKLIBRARY_H
#define SMKLIBRARY_H

#include <iostream>

template <typename T>
void array_print(const T * array[], int size);

#endif
Run Code Online (Sandbox Code Playgroud)

SMKLibrary.cpp

#include "SMKLibrary.h"

template <typename T>
void array_print(const T * array[], int size) {
    int last = size - 1;
    for (int i = 0; i < last; i++) {
        std::cout << array[i] << " ";
    }
    std::cout << array[last] << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

有人可以向我解释为什么我有这个错误吗?

c++ arrays templates function

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

arrays ×1

c++ ×1

function ×1

templates ×1