【发布时间】:2014-04-07 06:57:50
【问题描述】:
我在声明嵌套类时遇到问题。我的问题是如何正确声明嵌套类并调用其成员。我试过用谷歌搜索它并尝试了不同的方法,但我似乎无法让它工作。现在我在 LongInt::Digit{
这就是我正在尝试的:
头文件
class LongInt {
public:
class Digit{
public:
int data;
Digit(int d);
};
// Constructor
LongInt();
};
Cpp 文件
#include <iostream>
#include "LongInt.h"
using namespace std;
LongInt::Digit{
Digit next;
Digit prev;
LongInt::Digit::Digit (int d) {
data = d;
next = NULL;
prev = NULL;
}
}
LongInt::Digit front;
LongInt::Digit back;
LongInt::Digit curr;
LongInt::LongInt() {
front = NULL;
back = NULL;
curr = NULL;
}
【问题讨论】:
-
看来你忘了关闭
LongIntclass -
对不起,它在我的代码中。我忘了把它复制到问题中。
-
还是少了一个分号
}; -
那里也有。对不起,我无法正确复制。包括警卫和其他所有东西也都在那里。
-
.cpp文件中的第一个代码块在语法上是错误的。你想做什么?
标签: c++ class nested-class