By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

How to use typedef in nesting class?

P: n/a
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::outB(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!

Jun 9 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"÷" <me***********@gmail.comwrote in message
news:11*********************@q19g2000prn.googlegro ups.com...
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::outB(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
Jun 9 '07 #2

P: n/a
On 6 10 , 1 18 , "Mike Wahler" <mkwah...@mkwahler.netwrote:
"÷" <meiyantaos...@gmail.comwrote in message

news:11*********************@q19g2000prn.googlegro ups.com...


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::outB(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!

Jun 10 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.