473,387 Members | 1,561 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,387 software developers and data experts.

pointer to class with nested class

1
Hello everybody:

i have a question, and it's about using a pointer (just one declared) pointing to a class that has a nested class, the example code is like this:

Expand|Select|Wrap|Line Numbers
  1. class a_class{
  2.    int *a;
  3.    public:
  4.       class b_class{
  5.          int *b;
  6.          public:
  7.             b_class(){
  8.                b = new int;
  9.                *b = 3;}
  10.       };
  11. };
i know dat with pointers inside a class i should create constructors, but let us just skip that part, because isn't part of the problem; so when i created a pointer to the main class called a_class was like this:

Expand|Select|Wrap|Line Numbers
  1. a_class *ptr = new a_class;
and after i made something like this:

Expand|Select|Wrap|Line Numbers
  1. a_class::b_class *ptr2 = new a_class::b_class;
so this will create a pointer for the b_class alone, but i want to know how to do in just one pointer, i mean in *ptr, work with the b_class, being in the public part in a_class and the elements of b_class having them in the private, like in the example that i wrote up, because i tried something like this:

Expand|Select|Wrap|Line Numbers
  1. ptr::b_class->b_class();
and the same with
Expand|Select|Wrap|Line Numbers
  1. ptr->b_class->b_class();
or
Expand|Select|Wrap|Line Numbers
  1. ptr->b_class.b_class();
i don't know how to do it, i tried a lot of combinations and nothing, if anybody knows the answer please let me know, one more question, how it will be if b_class is nested in the private section of a_class, and a final one, where is use nesting in classes, in the public or private section, or depends of what i want??

thxs for all
Dec 11 '07 #1
2 1633
You should have a member of a_class point to an instance of a_class::b_class.
Dec 12 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
Yes, the thing woth nested classes is tjat they have the scope of the enclosing class but are not members of the class.

You would need an a_class contructor to make a call to a b_class constructor to initialize a b_class object or pointer that is a member of a_class (i.e. a data member).
Dec 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Paul | last post by:
Hi all, Here is what I am trying to do. I have a parent class calling a child class. when one function in child class is called, i need to call parent class' function. How can I get parent class'...
6
by: marco_segurini | last post by:
Hi, the following sample code shows a compiler error I get trying to build some old code with the last CL compiler (vers 13.10.3077): //----- begin #include <iostream> namespace ns {
1
by: Tomas Sieger | last post by:
Hi all, I'm in doubt with the following code: class Base { public: class Nested {}; }; class Derived:public Base { public: class Nested {
2
by: Rui Maciel | last post by:
I've been fooling around with a test class and meanwhile I stumbled on a pointer problem. I have two classes, one being nested in the other. I've wrote a method in the nested class that would...
13
by: Protoman | last post by:
Here's a non intrusive reference counting smart pointer class I'm working on; I keep getting a "22 C:\Dev-Cpp\SmrtPtr.hpp ISO C++ forbids declaration of `SmrtPtrDB' with no type" error. Code: ...
8
by: flamexx7 | last post by:
Can anybody tell me what is wrong with declaration of pointer p ? template<class Tclass Stack { struct Link { T* data; Link* next; Link(T* dat, Link* nxt) : data(dat), next(nxt) {} }* head;...
0
by: ivan.leben | last post by:
I am writing this in a new thread to alert that I found a solution to the problem mentioned here: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8 and to avoid...
7
by: Russell Mangel | last post by:
/* Hi, I am trying to hold a reference to un-managed pointer IStorage. The client/callers will make many accesses to IStorage, but only in-directly. For performance reasons IStorage needs to...
4
by: Immortal_Nephi | last post by:
I had a lot of research to see how function pointer works. Sometimes, programmers choose switch keyword and function in each case block can be called. Sometimes, they choose ordinary function...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.