解决方法:我永远也搞不清楚为什么在这里初始化堆栈时会出现错误:
#include "stack.h"
#include "linkList.h"
Stack::Stack() : m_top(0), m_size(0)
{
m_stack = new List(); // cannot assign m_stack this way. How do i initialize here?
}根据Intellisense,语法错误如下:
Error: a value of type List* cannot be assigned to an entity of type List*stack类如下所示:
#ifndef stack_H
#define stack_H
#include "linkList.h"
class Stack
{
public:
//
// Constructor to initialize stack data
//
Stack();
//
// functionality to determine if stack is empty
//
bool isEmpty();
//
// methods for pushing data on to stack and for
// popping data from the stack
//
void push(Node* current, int newValue);
void pop();
private:
//
// member data which represent the stack, the top
// of the stack and the size of the stack
//
Node* m_top;
List* m_stack;
unsigned m_size;
};
#endif我知道linkList类可以工作,因为我之前测试过它。如果我想创建一个新的列表,我所要做的就是:
List* myList = new List();解决方法:现在我得到了一些令人恼火的链接器错误,我不知道为什么:
1>------ Build started: Project: Stack, Configuration: Debug Win32 ------
1>Build started 10/10/2011 4:50:24 PM.
1>InitializeBuildStatus:
1> Touching "Debug\Stack.unsuccessfulbuild".
1>ClCompile:
1> myStack.cpp
1> linkList.cpp
1> Generating Code...
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Users\Dylan\documents\visual studio 2010\Projects\Stack\Debug\Stack.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.为了确保我的栈头文件不会与STL或其他文件冲突,我将其重命名为myStack.h (是的,开始大笑):
#ifndef myStack_H
#define myStack_H发布于 2011-10-11 08:00:14
此错误:
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup通常在项目设置错误时发生。我猜您正在编写一个控制台应用程序,但您选择了其他项目类型,而不是控制台应用程序。
发布于 2011-10-11 08:04:51
此链接器错误
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Users\Dylan\documents\visual studio 2010\Projects\Stack\Debug\Stack.exe : fatal error LNK1120: 1 unresolved externals意味着链接器找不到main()函数。你正在尝试制作一个可执行文件,所以你必须有一个main()。
此外,您似乎已将原始问题编辑为其他问题。这非常令人困惑,因为问题和答案/评论不再匹配。如果你遇到另一个问题,就开始一个新的问题。
https://stackoverflow.com/questions/7719748
复制相似问题