失踪 ”;”在标识符“name”之前,即使它在那里

时间:2015-02-15 22:11:14

标签: c++ syntax

这是我的代码:

 #ifndef PROBLEM3_H
 #define PROBLEM3_H

 #include <string>

 struct stackItem {
     // arbritary name do define item
     string name;
 };

 class Hw3Stack {
     public:
         // Default constuctor that prompts the user for the stack
         // capacity, initalizes the stack with the capacity, and the sets
         // the size of zero.
         Hw3Stack();

         // Copy constructor that takes a current stack and copies the
         // current size, capacity, and stackItems into the current object.
         Hw3Stack(Hw3Stack& stack);

         // Destructor that deletes the stack
         ~Hw3Stack();

         // Returns true if there are no items in stack, false otherwise.
         bool isEmpty();

         // Returns the current size of Hw3Stack
         int getSize();

         // Returns the current capacity of the stack.
         int getCapacity();

         // Adds the stackItem to the stack. If the stack is equal to
         // the capacity after insertion, copy all of the current 
         // stackItems into a new array with double the current capacity
         // and set the current stack array to the new array.
         void push(stackItem item);

         // Removes the top stackItem. Returns true if sucessful. Returns 
         // false otherwise (i.e. if the stack is empty).
         bool pop();

         // Returns a reference to the top stackItem, but does not remove
         // the top stackItem. If empty, you may return nullptr.
         stackItem* top();

         // Prints the stack contents’ names from top to bottom.
         void printStack();

     private:
         int capacity; // capacity of the stack
         int size; // current size of the stack
         stackItem* stack; // pointer to the array stack
 };

 int problem3();

 #endif PROBLEM3_H

我收到以下错误:

错误C2146:语法错误:缺少&#39;;&#39;在标识符&#39; name&#39;

之前

错误C4430:缺少类型说明符 - 假设为int。注意:C ++不支持default-int

我不知道这里出了什么问题,因为我以为我正确地编写了代码。 Visual Studio在编译之前没有告诉我有任何错误,所以任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:6)

您需要使用:

std::string name;