gpt4 book ai didi

c++ - 错误 LNK2019 : unresolved external symbol _main referenced in function ___tmainCRTStartup

转载 作者:IT老高 更新时间:2023-10-28 13:22:53 25 4
gpt4 key购买 nike

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

头文件

#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];
}

}

最佳答案

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

Project -> Properties -> Configuration Properties -> Linker -> System

并将 SubSystem 更改为 Console。

关于c++ - 错误 LNK2019 : unresolved external symbol _main referenced in function ___tmainCRTStartup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4845410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com