Tarun
Tarun

Reputation: 349

I want to create object of inner class in C++, or may be nested class

Suppose I have outer class as A and a inner class B

template <class T, class K>
class A::public T::RadioSignal, public VarMethod<T> {
private:
B *bObject;
public:
class B : public std::vector<SamplePoint*>
    {
    public:
        B(A<K, T> *outerInstance);
    };
}

I am getting below error: Unknown type name 'B'

Upvotes: 0

Views: 221

Answers (1)

Ped7g
Ped7g

Reputation: 16596

That error is at line B *bObject; ? But at that moment the class B is not yet defined.

Either define the inner class ahead of it, or use forward reference. (class B; is probably enough?)

edit: if you would use not only pointer, but also something more of B (like B bObject; -> class B; would be not sufficient, but as you are using only B *, it should be enough just to forward declare existence of the class B. Then again, I would try to stay away from bare pointer usage, why don't you declare the full class B first and then declare directly B bObject; as member instance of A? So you don't have to deal with new/delete.

Upvotes: 2

Related Questions