最初有效(文件init.cpp
):
#include "main.h"
#include "api/llemu.h"
#include "api/lcd.hpp"
template<typename ... Args>
void lcd_print(std::int16_t line,std::string fmt,Args ...args){
const char* format = convert(fmt,args...);
if (line >= 1 && line <= 8) {
llemu::editLabel(lines[line - 1], format);
}
}
void initialize() {
llemu::init();
lcd_print(1,"hey");
}
但是当我尝试在hpp
文件中实现功能模板时,它不起作用。新代码:
//init.cpp
#include "main.h"
#include "api/llemu.h"
#include "api/lcd.hpp"
void initialize() {
llemu::init();
lcd_print(1,"hey");
}
//lcd.hpp
template<typename ... Args>
void lcd_print(std::int16_t line,std::string fmt,Args ...args);
//lcd.cpp
template<typename ... Args>
void lcd_print(std::int16_t line,std::string fmt,Args ...args){
const char* format = convert(fmt,args...);
if (line >= 1 && line <= 8) {
llemu::editLabel(lines[line - 1], format);
}
}
新代码中存在链接器错误:
[undefined reference to `void lcd_print<>(short, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)]
这是什么意思,我做错了什么?