Can someone give me a example about how to define a new type of struct in a class in C++.Thanks.
+11
A:
Something like this:
class Class {
// visibility will default to private unless you specify it
struct Struct {
//specify members here;
};
};
sharptooth
2010-03-30 06:24:35
+2
A:
Something like:
class Tree {
stuct node {
int data;
node *llink;
node *rlink;
};
.....
.....
};
codaddict
2010-03-30 06:26:16
+1
A:
// declare class & nested struct
class C {
// struct will be private without `public:` keyword
struct S {
int sa;
void func();
};
void func();
};
// if you want to separate the implementation (definition)
void C::func() {
// implementaiton here
}
void C::S::func() {
// implementation here
}
// if you want to inline the implementation, other answers will do fine.
afriza
2010-03-30 06:43:55