Initializing a class to a pointer?

I came across a piece of c++ code that seems to be initializing a class object like this:

ImapMailbox *mailbox;

Now the class looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class ImapMailbox {
    public:
        ImapMailbox();
        ImapMailbox (const QString& mailbox);
        ~ImapMailbox();

        // Methods
        void addMessage (ImapMessage *message);
        void clearMessages (void);
        
        // Properties
        QString name (void) const;
        void setName (const QString& name);
        
        int exists (void) const;
        void setExists (int exist);
        
        int recent (void) const;
        void setRecent (int recent);
        
        int unseen (void) const;
        void setUnseen (int unseen);

        bool isReadWrite (void) const;
        void setReadWrite (bool readWrite);
                
        ImapMessageFlags flags (void) const;
        void setFlags (const QString& flags);
        void setFlags (ImapMessageFlags flags);
        
        ImapMessage *takeAt (int index);
        ImapMessage *at (int index) const;
        QList<ImapMessage *> messages (void) const;
        ImapMessage *findById (int messageId) const;

    private:
        ImapMailboxPrivate *d;
};


And the constructor looks like this:

1
2
3
4
5
6
7
ImapMailbox::ImapMailbox()
    : d(new ImapMailboxPrivate)
{
    d->unseen = d->exists = d->recent = 0;
    d->readWrite = false;
    d->flags = 0;
}


But this does not seem to be an array like object. So what exactly could this be pointing to?
ImapMailbox *mailbox;

This doesn't create an object, all it does is create a pointer to an object.
A pointer is either a 32 bit or a 64 bit integer that can hold the location of data. The type of the pointer is only used by the compiler to determine how much data is stored and what functions it can access. You do not have to allocate the memory for the actual object if you have a pointer to an (inexistant) object.
Topic archived. No new replies allowed.