如何显式实例化可变参数模板函数? C ++

时间:2018-12-12 15:30:52

标签: c++

h个文件:

示例功能:

CREATE TABLE T(Col varchar(100))

INSERT INTO T VALUES
('Sample Name Test'),
('Sample Name S'),
('Name S Sample2');

WITH C AS(
SELECT Col,
       LEFT(Col, CHARINDEX(' ', Col, 1)-1) As Part1,
       RIGHT(Col, CHARINDEX(' ', REVERSE(Col), 1)-1 ) As Part3
FROM T
),
CC AS
(
  SELECT C.Part1,
     REPLACE(SUBSTRING(C.Col, LEN(C.Part1)+2,  LEN(C.Col)) , C.Part3, '') As Part2, 
     C.Part3
  FROM C
)

SELECT DISTINCT
       Part1 Consultant_Last_Name,
       CASE WHEN LEN(Part2) < LEN(Part3) THEN Part3
            ELSE Part2
       END Consultant_First_Name
FROM CC;

尝试:

template<typename... Args>
std::string print(const char *format, Args... args);

cpp文件:

extern template std::string print(const char *, const char *);
extern template std::string print(const char *, const char *, int);

我知道

  

x86_64体系结构的未定义符号

1 个答案:

答案 0 :(得分:0)

实例化声明很好,但是定义也需要实例化。将它们添加到您的cpp文件中:

template<typename... Args>
string print(const char *format, Args... args) {
    return string;
}

template std::string print(const char *, const char *);
template std::string print(const char *, const char *, int);

现在还将定义这些功能。如果您正确进行链接,链接应会找到它们。