[英]C++ stack implementation (homework)
SOLVED: I cannot for the life of me figure out why I get an error when trying to initialize the stack here: 求助:我不能为我的生活弄清楚为什么我在这里尝试初始化堆栈时出现错误:
#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?
}
The syntax error according to Intellisense is as follows: 根据Intellisense的语法错误如下:
Error: a value of type List* cannot be assigned to an entity of type List*
The stack class is here: 堆栈类在这里:
#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
I know that the linkList class works because I tested it out before. 我知道linkList类可以工作,因为我之前测试过它。 If I wanted to create a new list, all I have to do is:
如果我想创建一个新列表,我所要做的就是:
List* myList = new List();
SOLVED: Now I am getting some infuriating linker errors, and I cant figure out why: 已解决:现在我收到了一些令人愤怒的链接器错误,我无法找出原因:
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.
To make sure my stack header file was not in conflict with STL's or whatever, I renamed it myStack.h (yes, begin laughing): 为了确保我的堆栈头文件与STL或其他任何东西没有冲突,我将其重命名为myStack.h(是的,开始笑):
#ifndef myStack_H
#define myStack_H
This error : 这个错误:
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
Usually happens when your project is wrongly setup. 通常在您的项目设置错误时发生。 I guess that you are writing a console app but you have selected as type of project something else than a console app.
我猜你正在编写一个控制台应用程序,但你选择的项目类型不是控制台应用程序。
This linker error 此链接器错误
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
means that the linker can't find a main() function. 表示链接器找不到main()函数。 You're trying to make an executable, so you have to have a main().
你正在尝试创建一个可执行文件,所以你必须有一个main()。
Also, it appears you've edited your original question to now be something else. 此外,您似乎已经编辑了原始问题,现在还有其他问题。 That's extremely confusing because the question and answers/comments no longer match.
这非常令人困惑,因为问题和答案/评论不再匹配。 Start a new question if you run into another issue.
如果您遇到另一个问题,请开始一个新问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.