简体   繁体   English

嵌套类的前向声明

[英]Forward declaration of a nested class

I am trying to forward delcare this nested class, I already tried it but i didnt work. 我正在尝试转发delcare这个嵌套的类,我已经尝试过了,但是我没有工作。 When i try to forward declare i get cant acces private member errors, so I guess i am doing something wrong. 当我尝试转发声明时,我无法访问私人成员错误,因此我想我做错了。

#ifndef PLAYERHOLDER_H
#define PLAYERHOLDER_H

#include <QtCore>
#include <player.h>
#include <datasource.h>

class PLAYERHOLDER
{

private:
class CONTACTMODEL : public QAbstractTableModel
{
public:
    explicit CONTACTMODEL(PLAYERHOLDER* holder);

    int rowCount( const QModelIndex &parent ) const;
    int columnCount( const QModelIndex &parent ) const;
    QVariant data( const QModelIndex &index, int role ) const;
    QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
    void update();


private:
    static PLAYERHOLDER* m_playerHolder;
};

public:
static PLAYERHOLDER* getInstance();
void createPlayer(PLAYER *player);
void updatePlayer(int id);
void deletePlayer(int id);
PLAYER* findPlayer(int id);
void loadPlayers(int teamid);

QAbstractItemModel* model() ;

private:
PLAYERHOLDER();
static PLAYERHOLDER *thePlayerholder;
QHash<int, PLAYER*> playerlist;
DATASOURCE *datasource;
mutable CONTACTMODEL *m_model;
};

#endif // PLAYERHOLDER_H

But i dont know how to do it, i searched around and still dont know it :( Is it possible to forward declare this? 但是我不知道该怎么做,我四处搜寻,但仍然不知道:(是否可以向前声明?

The nested type is part of the enclosing type. 嵌套类型是封闭类型的一部分。 That means that it cannot be forward declared by itself, but it can be declared in the definition of the enclosing type, and then defined outside: 这意味着它本身不能被前向声明,但是可以在封闭类型的定义中声明,然后在外部定义:

class enclosing {
   class inner;          // Forward declaration
};
// Somewhere else
class enclosing::inner { // Definition
   int x;
};

What you cannot do is forward declare the inner type outside of the definition of the enclosing type: 您不能做的是在封闭类型的定义之外向前声明内部类型:

class enclosing::outer;  // Error

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM