Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 类声明后出现编译错误,Main不';";见;班级_C++_Class_Compiler Errors - Fatal编程技术网

C++ 类声明后出现编译错误,Main不';";见;班级

C++ 类声明后出现编译错误,Main不';";见;班级,c++,class,compiler-errors,C++,Class,Compiler Errors,我遇到了一个错误,涉及到下面的类 #ifndef STACKLL #define STACKLL #include <iostream> using namespace std; template <class T> class STACKLL { private: struct NODE { T info; NODE *next; }; NODE *Stack; public: STACKL

我遇到了一个错误,涉及到下面的类

#ifndef STACKLL
#define STACKLL
#include <iostream>
using namespace std;
template <class T>
class STACKLL
{
private: struct NODE
         {
             T info; NODE *next;
         };
         NODE *Stack;
public: STACKLL()
        {Stack = NULL;}
        void Push (T x)
        {
            NODE *p = new (NODE);
            p -> info = x;
            p -> next = Stack;
            Stack = p;
        }
        T Pop()
        {
        NODE *p = Stack;
        T x = p -> info;
        Stack = p -> next;
        delete (p);
        return x;
        }
        bool Empty()
        {return (Stack == NULL)?true:false;}
};
#endif
\ifndef STACKLL
#定义STACKLL
#包括
使用名称空间std;
模板
STACKLL类
{
私有:结构节点
{
T信息;节点*下一步;
};
节点*堆栈;
公众:STACKLL()
{Stack=NULL;}
无效推力(T x)
{
节点*p=新(节点);
p->info=x;
p->next=堆栈;
堆栈=p;
}
T Pop()
{
节点*p=堆栈;
tx=p->info;
Stack=p->next;
删除(p);
返回x;
}
bool Empty()
{return(Stack==NULL)?true:false;}
};
#恩迪夫
这是主程序中使用的类

#include <iostream>
#include "STACKLL.h"
using namespace std;
int main ()
{
    STACKLL <int> s;
    int a[5] = {3,9,8,5,7}, sum=0, nodecount=0;
    for (int i = 0; i < 5; ++i)
        s.Push (a[i]);
    while (!s.Empty())
    {
        int c = s.Pop();
        cout << c << "->";
        sum += c;
        nodecount++;
    }
    cout << "NULL\n";
    cout << "Sum of nodes = " << sum << endl;
    cout << "There are " << nodecount << " nodes\n";
#包括
#包括“STACKLL.h”
使用名称空间std;
int main()
{
斯塔克尔斯;
INTA[5]={3,9,8,5,7},和=0,节点计数=0;
对于(int i=0;i<5;++i)
s、 推(a[i]);
而(!s.Empty())
{
int c=s.Pop();

您以前可以定义一个名为
STACKLL
的空宏,然后尝试创建一个名为
STACKLL
的类。预处理器将从程序中删除
STACKLL
,因此您得到以下结果:

class
{
    ...
这显然是一个语法错误

对于第二个问题,也是一样的。预处理器删除
STACKLL
,因此得到
s;
,这显然也是一个语法错误

希望这有帮助


-Alex

您之前定义了一个名为
STACKLL
的空宏,然后尝试创建一个名为
STACKLL
的类。预处理器从程序中删除
STACKLL
,因此您得到以下结果:

class
{
    ...
这显然是一个语法错误

对于第二个问题,也是一样的。预处理器删除
STACKLL
,因此得到
s;
,这显然也是一个语法错误

希望这有帮助


-Alex

对。编译器正在将every
STACKLL
扩展为空字符串。对。编译器正在将every
STACKLL
扩展为空字符串。