C++堆栈实现(作业)
C++ stack implementation (homework)
已解决:我一辈子都无法弄清楚为什么我在尝试初始化这里的堆栈时出错:
#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*
堆栈类在这里:
#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 "DebugStack.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:UsersDylandocumentsvisual studio 2010ProjectsStackDebugStack.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
为了确保我的堆栈头文件不与STL或其他文件冲突,我将其重命名为myStack.h(是的,开始大笑(:
#ifndef myStack_H
#define myStack_H
此错误:
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
通常发生在项目设置错误时。我猜你正在写一个控制台应用程序,但你选择了控制台应用程序以外的其他项目类型。
此链接器错误
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:UsersDylandocumentsvisual studio 2010ProjectsStackDebugStack.exe : fatal error LNK1120: 1 unresolved externals
意味着链接器找不到main((函数。您正试图制作一个可执行文件,因此必须有一个main((。
此外,您似乎已将原来的问题编辑为其他问题。这非常令人困惑,因为问题和答案/评论不再匹配。如果你遇到另一个问题,就提出一个新问题。
相关文章:
- 如果没有malloc,链表实现将失败
- 如何在c++中实现处理器调度模拟器
- 如何在c++中使用引用实现类似python的行为
- 实现无开销push_back的最佳方法是什么
- 使用简单类型列表实现的指数编译时间.为什么
- 如何在BST的这个简单递归实现中消除警告
- 实现一个在集合上迭代的模板函数
- 我应该实现右值推送功能吗?我应该使用std::move吗
- 如何正确实现和访问运算符的各种自定义枚举器
- C++Union/Struct位域的实现和可移植性
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 在c++中实现LinkedList时,应出现未处理的错误
- 为左值和右值的包装器实现C++范围
- 使用模板进行堆栈实现; "name followed by :: must be a class or namespace"
- 将执行、作业和WinAPI相乘
- 不知道如何在家庭作业任务中实现一件事
- 如何实现/模拟作业调度器
- C++堆栈实现(作业)
- c++栈实现(家庭作业)
- 如何实现shell的作业控制