Hello,

I'm programming in C++. Is it possible to have a private data member of type class X within the definition of class X? For example,

class X
{
    ...
    private:
    X m_member;
    ...
}

I'm pretty sure it's not possible, but I appreciate any feedback.

-price

>I'm pretty sure it's not possible
It's possible, but not like that. You can have a pointer or a reference to the class being defined:

class X {
  X *m_member;
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.