错误 LNK2019:未解析的外部符号 _main 在函数 ___tmainCRTStartup 中引用

新手上路,请多包涵

我不知道它有什么问题..我找不到错误在哪里,注释掉实现也不能解决错误。

头文件

#ifndef MAIN_SAVITCH_SEQUENCE_H
#define MAIN_SAVITCH_SEQUENCE_H
#include <cstdlib>  // Provides size_t

namespace main_savitch_3
{
    class sequence
    {
    public:
        // TYPEDEFS and MEMBER CONSTANTS
        typedef double value_type;
        typedef std::size_t size_type;
        static const size_type CAPACITY = 30;
        // CONSTRUCTOR
        sequence( );
        // MODIFICATION MEMBER FUNCTIONS
        void start( );
        void advance( );
        void insert(const value_type& entry);
        void attach(const value_type& entry);
        void remove_current( );
        // CONSTANT MEMBER FUNCTIONS
        size_type size( ) const;
        bool is_item( ) const;
        value_type current( ) const;
    private:
        value_type data[CAPACITY];
        size_type used;
        size_type current_index;
    };
}

#endif

资源

#include "sequence1.h"
#include <assert.h>

namespace main_savitch_3
{

    // Default constructer - sequence is empty
    sequence::sequence()
    {
        used = current_index = 0;
    }

    // Start the iteration
    void sequence::start()
    {
        current_index = 0;
    }
    // Iterate
    void sequence::advance()
    {
        current_index++;
    }

    // Number of items in the sequence
    sequence::size_type sequence::size() const
    {
        return used;
    }
    // Checks if there is a current item
    bool sequence::is_item() const
    {
        return current_index <= used && used > 0;
    }
    // Returns the current value
    sequence::value_type sequence::current() const
    {
        assert(is_item()); // no current item
        return data[current_index];
    }

    // Adds an item BEFORE the current index
    void sequence::insert(const value_type& entry)
    {
        assert(entry != 0); // pointer is invalid
        assert(current_index < sequence::CAPACITY); // no room to add an item

        // move items up - starting with the last item and working down to the current item
        // arrays start at 0, so the -1 adjusts it
        for (size_type i = used - 1; i >= current_index; i--)
            data[i + 1] = data[i];

        data[current_index] = entry;
    }
    // Adds an item AFTER the current index
    void sequence::attach(const value_type& entry)
    {
        assert(entry != 0); // pointer is invalid
        assert(current_index < sequence::CAPACITY); // no room to add an item

        // move items up - starting with the last item and working down to the current item
        // arrays start at 0, so the -1 adjusts it
        for (size_type i = used - 1; i > current_index; i--)
            data[i + 1] = data[i];

        if (current_index = 0)
            data[used] = entry;
        else
            data[current_index + 1] = entry;
    }
    // Removes the current item
    void sequence::remove_current()
    {
        for (size_type i = current_index; i < used; i++)
            data[i] = data[i + 1];
    }

}

原文由 Caleb Jares 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 321
2 个回答

即使您的项目有 main() 方法,链接器有时也会感到困惑。您可以在 Visual Studio 2010 中解决此问题,方法是转到

项目 -> 属性 -> 配置属性 -> 链接器 -> 系统

并将 SubSystem 更改为控制台。

原文由 Caleb Jares 发布,翻译遵循 CC BY-SA 3.0 许可协议

我的上下文:Visual Studio

当我添加扩展名错误的现有文件(如 *.ccc)时,我遇到了同样的问题。

比我将扩展名更改为 *.cpp。当我构建解决方案时,我遇到了类似的链接错误。

当我查看 *.vcxproject 文件时,我发现了原因。该文件尚未被 Visual Studio 识别为源文件,因此将其放入 ClInclude 组(见下文)。

     <ItemGroup>
        <ClInclude Include="toto.cpp" />
    </ItemGroup>

我将它移到 ClCompile 组(见下文)并重建没有错误。

     <ItemGroup>
        <ClCompile Include="AnotherSource.cpp" />
        <ClCompile Include="toto.cpp" />
    </ItemGroup>

原文由 CCP 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题