How to use typedef in nesting class?

  • Thread starter =?gb2312?B?w7fR08zO?=
  • Start date
?

=?gb2312?B?w7fR08zO?=

Hi,sir,please look at this code.
///////////////////////////////////////////////////
#include <iostream>

using namespace std;


class A{
private:
class B;//
public:
int out(int x){
return outB(x)->a;
}
B * outB(int x);
private:

B* root;
class B{
int a;
B(int init_a) :a(init_a){}
friend class A;
};

};

A::B* A::eek:utB(int x){
root = new B(x);
return root;
}

int main(int argc, char *argv[])
{
A a1;
cout<<a1.out(8)<<endl;

}

//////////////////////////////////////////////////////////////////////////////////////
I want to use
"typedef A::B C;"
to make the code more readable.
But I don't know where should I put typedef?
Thank you very much!
 
M

Mike Wahler

÷ÑÓÌÎ said:
Hi,sir,please look at this code.
///////////////////////////////////////////////////
#include <iostream>

using namespace std;


class A{
private:
class B;//
public:
int out(int x){
return outB(x)->a;
}
B * outB(int x);
private:

B* root;
class B{
int a;
B(int init_a) :a(init_a){}
friend class A;
};

};

A::B* A::eek:utB(int x){
root = new B(x);
return root;
}

int main(int argc, char *argv[])
{
A a1;
cout<<a1.out(8)<<endl;

}

//////////////////////////////////////////////////////////////////////////////////////
I want to use
"typedef A::B C;"
to make the code more readable.
But I don't know where should I put typedef?

Put it in the scope(s) where you intend to use it.

-Mike
 
A

A Loser

Hi,sir,please look at this code.
///////////////////////////////////////////////////
#include <iostream>
using namespace std;
class A{
private:
class B;//
public:
int out(int x){
return outB(x)->a;
}
B * outB(int x);
private:
B* root;
class B{
int a;
B(int init_a) :a(init_a){}
friend class A;
};

A::B* A::eek:utB(int x){
root = new B(x);
return root;
}
int main(int argc, char *argv[])
{
A a1;
cout<<a1.out(8)<<endl;

///////////////////////////////////////////////////////////////////////////­///////////
I want to use
"typedef A::B C;"
to make the code more readable.
But I don't know where should I put typedef?

Put it in the scope(s) where you intend to use it.

-Mike- -

Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,293
Messages
2,571,505
Members
48,192
Latest member
LinwoodFol

Latest Threads

Top