首页 文章

C链接对象的文件(G)

提问于
浏览
1

class.h

#include <iostream>
#include <stdint.h>

using namespace std;

template <typename T>
class CIntegerType {
 public:
    void Show ( void );

 private:
    T m_Data;
};

class.cpp

#include "class.h"

template <typename T>
void CIntegerType<T> :: Show ( void ) {
    cout << m_Data << endl;
}

main.cpp

#include "class.h"

int main ( void ) {
    CIntegerType<uint32_t> UINT32;

    UINT32 . Show ();

    return 0;
}

此命令返回:

g -Wall -pedantic -c main.cpp

g -Wall -pedantic -c class.cpp

g -Wall -pedantic -o class.o main.o

main.o:在函数`main'中:main.cpp :( . text 0x11):未定义引用'CIntegerType <unsigned int> :: Show()'collect2:ld返回1退出状态

2 回答

相关问题