Linker抱怨“未解决的外部符号”

Linker complaining about “unresolved external symbol”

本文关键字:外部 符号 未解决 抱怨 Linker      更新时间:2023-10-16
  • sequence_test.cpp(测试调试器驱动程序)的完整代码

  • sequence2.cpp(实现文件)的完整代码

这是头文件代码

#ifndef SEQUENCE_H
#define SEQUENCE_H
#include <cstdlib>  // Provides size_t
namespace CISP430_A2
{
    class sequence
    {
    public:
        // TYPEDEFS and MEMBER CONSTANTS
        typedef double value_type;
        typedef size_t size_type;
        enum { CAPACITY = 30 };
        // CONSTRUCTOR
        sequence(size_type entry=CAPACITY )
        {
            for(int i=0;i<CAPACITY;i++)
                data[i]=0;
            used=0;
            capacity=CAPACITY;
            current_index=0;
        }
           // COPY CONSTRUCTOR
        sequence(const sequence& entry);       
    // Library facilities used: cstdlib
        // MODIFICATION MEMBER FUNCTIONS
        void start( );
        void advance( );
        void insert(const value_type& entry);
        void attach(const value_type& entry);
        void remove_current( );
        void resize(size_type new_capacity);
        void sequence::operator =(const sequence& entry);
        // CONSTANT MEMBER FUNCTIONS
        size_type size( ) const;
        bool is_item( ) const;
        value_type current( ) const;
        //Destructor
         ~sequence(){}
    private:
        value_type data[CAPACITY];
        size_type used;
        size_type capacity;
        size_type current_index;
    };
}
#endif

我当前收到此链接器错误:

sequence_test.obj:错误LNK2019:未解析的外部符号"public: __thiscall CISP430_A2::sequence::sequence(unsigned int)"(??0sequence@CISP430_A2@@QAE@I@Z) 在函数_main 中引用

我刚刚尝试并成功编译了您的文件,所以它不在您的代码中(至少不在您发布的部分中)

我想,你在用Visual Studio吧?尝试以下

  • 确保项目设置正确(项目中包含的所有文件?)
  • 你使用预编译的头吗?试着把它们关掉
  • 尝试干净的重建