我不知道它有什么问题.我无法找到错误的位置,注释掉实现并没有解决错误.
头文件
#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
Run Code Online (Sandbox Code Playgroud)
资源
#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];
}
}
Run Code Online (Sandbox Code Playgroud)
Cal*_*res 72
即使您的项目有main()方法,链接器有时也会感到困惑.您可以转到,在Visual Studio 2010中解决此问题
项目 - >属性 - >配置属性 - >链接器 - >系统
并更改SubSystem 为控制台.
Ant*_*eev 37
我们也有这个问题.我的同事找到了解决方案.它变成了第三方库标题中"main"的重新定义:
#define main SDL_main
Run Code Online (Sandbox Code Playgroud)
所以解决方案是添加:
#undef main
Run Code Online (Sandbox Code Playgroud)
在我们的主要功能之前
这显然是愚蠢的!
Jam*_*lis 16
你需要一个main()函数,所以程序知道从哪里开始.
小智 9
万一有人错过了明显的事; 请注意,如果您构建GUI应用程序并在link-args中使用
" -subsystem:windows ",则应用程序条目为WinMain @ 16 .不是主().因此,您可以使用此代码段来调用main():
#include <stdlib.h>
#include <windows.h>
#ifdef __GNUC__
#define _stdcall __attribute__((stdcall))
#endif
int _stdcall
WinMain (struct HINSTANCE__ *hInstance,
struct HINSTANCE__ *hPrevInstance,
char *lpszCmdLine,
int nCmdShow)
{
return main (__argc, __argv);
}
Run Code Online (Sandbox Code Playgroud)
你实现了这个main()功能吗?
int main(int argc, char **argv) {
... code ...
return 0;
}
Run Code Online (Sandbox Code Playgroud)
[编辑]
您拥有main()另一个源文件,因此您可能忘记将其添加到项目中.
添加现有源文件:在" 解决方案资源管理器"中,右键单击" 源文件"文件夹,指向" 添加",然后单击" 现有项".现在选择包含的源文件main()
小智 6
如果您使用的是Visual Studio。之所以收到此错误,可能是因为您最初创建了一个新的头文件file.h,然后将其重命名为放置了main()函数的file.cpp。
要解决此问题,请右键单击file.cpp->单击“属性”,转到“
配置属性”->“常规”->“项目类型”,并将其值更改为C / C ++编译器而不是C / C ++标头。
小智 5
尽管我遇到了这个问题:
main(); 和我的最终修复如下:
main()在一个命名空间中,所以被有效地称为something::main()...删除这个命名空间解决了这个问题。我在 Visual Studio 2013 中处理 DLL 项目时遇到了 LNK2019 错误。
我在项目中添加了一个新配置。但是,visual studio 没有将“配置类型”作为“动态库”,而是将其添加为“应用程序”。这导致了 LNK2019 错误。
通过转到“项目”->“属性”->“配置属性”->“常规”并将“配置类型”更改为“动态库 (.dll)”并将“目标扩展名”更改为“.dll”,修复了 LNK2019 错误。
是的,最初的问题是关于控制台/应用程序项目,这与我的回答是不同的问题。但我相信添加这个答案可能会帮助那些偶然发现这个线程的人(像我一样)。
| 归档时间: |
|
| 查看次数: |
222373 次 |
| 最近记录: |