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

Eri*_*vas 1 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
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

错误C2146:语法错误:缺少';' 在标识符"名称"之前

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

我不知道这里出了什么问题因为我以为我正确编写了代码.Visual Studio在编译之前没有告诉我有任何错误,所以任何帮助都将不胜感激.

R S*_*ahu 6

你需要使用:

std::string name;
Run Code Online (Sandbox Code Playgroud)

  • 这就是我非常喜欢C++错误消息的原因. (3认同)