[英]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 "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
這個錯誤:
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:\Users\Dylan\documents\visual studio 2010\Projects\Stack\Debug\Stack.exe : fatal error LNK1120: 1 unresolved externals
表示鏈接器找不到main()函數。 你正在嘗試創建一個可執行文件,所以你必須有一個main()。
此外,您似乎已經編輯了原始問題,現在還有其他問題。 這非常令人困惑,因為問題和答案/評論不再匹配。 如果您遇到另一個問題,請開始一個新問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.