久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

“未定義符號"簡單模板類的鏈接器錯誤

quot;Undefined symbolsquot; linker error with simple template class(“未定義符號簡單模板類的鏈接器錯誤)
本文介紹了“未定義符號"簡單模板類的鏈接器錯誤的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

離開 C++ 幾年了,我從以下代碼中收到鏈接器錯誤:

Been away from C++ for a few years and am getting a linker error from the following code:

基因.h

#ifndef GENE_H_INCLUDED
#define GENE_H_INCLUDED

template <typename T>
class Gene {
    public:
    T getValue();
    void setValue(T value);
    void setRange(T min, T max);

    private:
    T value;
    T minValue;
    T maxValue;
};

#endif // GENE_H_INCLUDED

基因.cpp

#include "Gene.h"

template <typename T>
T Gene<T>::getValue() {
    return this->value;
}

template <typename T>
void Gene<T>::setValue(T value) {
    if(value >= this->minValue && value <= this->minValue) {
        this->value = value;
    }
}

template <typename T>
void Gene<T>::setRange(T min, T max) {
    this->minValue = min;
    this->maxValue = max;
}

如果對任何人都很重要,請使用 Code::Blocks 和 GCC.此外,為了好玩和練習,顯然將一些 GA 內容移植到 C++.

Using Code::Blocks and GCC if it matters to anyone. Also, clearly porting some GA stuff to C++ for fun and practice.

推薦答案

必須在實例化給定模板類之前包含模板定義(代碼中的 cpp 文件),因此您必須在標頭,或在使用類之前#include cpp 文件(或者如果數量有限,則進行顯式實例化).

The template definition (the cpp file in your code) has to be included prior to instantiating a given template class, so you either have to include function definitions in the header, or #include the cpp file prior to using the class (or do explicit instantiations if you have a limited number of them).

這篇關于“未定義符號"簡單模板類的鏈接器錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區別?)
Difference between const. pointer and reference?(常量之間的區別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問向量的內容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進行多態?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: av中文在线播放 | 日韩中文在线观看 | 国产日韩电影 | 日韩在线免费视频 | 欧美亚洲国产日韩 | 欧美aⅴ | 国产免费福利小视频 | 成人午夜网 | 亚州毛片 | 日韩中文在线 | 韩国av一区二区 | 欧美激情综合 | 日日夜夜免费精品视频 | 欧美一区二区三区高清视频 | a级在线观看 | 亚洲国产成人av好男人在线观看 | 美女久久久久久久 | 欧美在线视频一区二区 | 人人九九精 | 国产免费视频在线 | 成人一区二区在线 | 欧美视频免费在线观看 | 亚洲国产精品人人爽夜夜爽 | 精品国产免费一区二区三区演员表 | 精品一区二区免费视频 | a中文在线视频 | 精品国产一区二区国模嫣然 | 四虎成人精品永久免费av九九 | 青青草综合 | 亚洲欧美激情网 | 一区二区三区四区av | 日本不卡一区 | 久久久精品 | 午夜影院 | 久久午夜电影 | 日韩三级一区 | 国产成人精品一区二区三区四区 | 久久久成人动漫 | 欧美日韩在线观看一区二区三区 | 亚洲人成在线观看 | 欧美成人高清 |