Hi,

Is this valid in C++??

struct A{...};

class B: public A{...};

Thanks!

In C++ A Struct IS a Class. The only difference is that in a class, the members by default are private. In a Struct, they are by default public.

class base
{ protected:
struct node{};
};
class derived :public base
{
struct node *prev;
};

when i do this i 'm getting an error that prev is not a member of base::node.
what can i do if i want to declare an additional variable
of struct node type in class derived

richard bach, when I compile exactly what you have, i don't get a problem.
Using Visual Studio 2008. V.9.021022.8

#include <iostream>

using namespace std;


class base
{ protected:
struct node{};
};
class derived :public base
{
struct node *prev;
};


class A
{
   public:
      int a;
};

struct B : A { };

struct C
{
public:
      int c;
};

class D : public C { };

int main()
{
   B b;
   D d;
   b.a = 1;
   d.c = 2;
   cout << b.a << " " << d.c << endl;
}

I compile that and no errors, and I do actually get the numbers.
I don't know to what extend this works, but to this, it is working.

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.