CSmallEnemy::CSmallEnemy(int nRow, int nCol); ~CSmallEnemy();这里显示成员声明中不允许限定名怎么解决
时间: 2023-12-03 18:47:42 浏览: 35
在成员函数声明中不允许限定名的问题,可能是因为您在类定义的外部使用了限定名。您可以将成员函数的实现放在类定义的内部,或者使用类作用域解析运算符(::)来指定限定名。
例如,您可以将CSmallEnemy类的成员函数实现放在类定义内部:
```
class CSmallEnemy {
public:
CSmallEnemy(int nRow, int nCol) {
// constructor implementation
}
~CSmallEnemy() {
// destructor implementation
}
private:
int m_nRow;
int m_nCol;
};
```
或者,您可以使用类作用域解析运算符指定限定名:
```
class CSmallEnemy {
public:
CSmallEnemy(int nRow, int nCol);
~CSmallEnemy();
private:
int m_nRow;
int m_nCol;
};
CSmallEnemy::CSmallEnemy(int nRow, int nCol) {
// constructor implementation
}
CSmallEnemy::~CSmallEnemy() {
// destructor implementation
}
```
在成员函数的实现中,使用类作用域解析运算符来指定限定名(例如,CSmallEnemy::CSmallEnemy)。这样就可以避免成员函数声明中不允许限定名的问题。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)