473,320 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to use typedef in nesting class?

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
2 1395

"÷ÑÓÌÎ" <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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: CoolPint | last post by:
I read in books that nested class cannot access private members of nesting class and vice versa unless they are made friends. Somehow, my compiler is letting my nested class member functions access...
2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
5
by: Mr A | last post by:
Hi! I'm trying to do the following: emplate <typename Resource> class ResourceManager { public: typedef std::list<Resource*>::iterator Iterator; typedef std::list<Resource*>::const_iterator...
2
by: Plok Plokowitsch | last post by:
After over a decade of programming in C++ I seem to have missed some substantial point (mental note: am I getting too old for this?). A little bit of help would be *very* appreciated. I'm trying...
7
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type ...
4
by: kl.vanw | last post by:
I would like to count the nesting level in template classes. How can I make the following work? #include <assert.h> template <class T> class A { public: A() { // what goes here?
5
by: Alan Woodland | last post by:
Hi, I don't think I can't do this directly with standard C++, I've tried all the ways I could think of that make sense and then some. I was wondering if someone had a genius idea how I could...
3
by: aaragon | last post by:
Hello everyone, I'm trying to run some simple code but for some reason it doesn't work and I've been staring at it for a long time without a single clue of what's going on. This is what happens,...
17
by: henry | last post by:
Folks Here's a skeleton, generic HTML page, call it "index.php". You'll see a bit of php code in the middle: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.