【问题标题】:Missing ";" before identifier "name" even though it's there失踪 ”;”在标识符“名称”之前,即使它在那里
【发布时间】:2015-04-16 09:28:16
【问题描述】:

这是我的代码:

 #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:语法错误:缺少 ';'在标识符“名称”之前

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

我不知道这里出了什么问题,因为我认为我正确地编写了代码。 Visual Studio 不会在编译之前告诉我有任何错误,因此我们将不胜感激。

【问题讨论】:

标签: c++ syntax


【解决方案1】:

你需要使用:

std::string name;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-13
    • 1970-01-01
    相关资源
    最近更新 更多