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

How to make Nested class, which use default constructor parameters?

osfreak
22
Expand|Select|Wrap|Line Numbers
  1.  
  2. class Outer
  3. {
  4. public:
  5.     int outera;
  6.  
  7.     class Inner{
  8.  
  9.     public:
  10.         static int a,b;
  11.         int c;
  12.         void Displaystatvalue();
  13.         Inner(int parm = 0):c(parm)
  14.         {
  15.         }
  16.  
  17.     }in1;         //}in1(15);//Not allowed why
  18.         Inner in2;   //Inner in2(10);//not allowed,why?
  19.  
  20. };
  21.  
  22.  
  23.  
  24.  
Jun 16 '10 #1
2 2758
weaknessforcats
9,208 Expert Mod 8TB
in1 and in2 are member variables. in(15) and in2(10) are constructor calls. That is, actual code that executes and allocates memory. in(15)and in2(10) are , therefore definitions (objects created at run time), and you cannot have definitions inside a declaration because there's no way to make those calls at compile time.
Jun 16 '10 #2
Banfa
9,065 Expert Mod 8TB
If you want to initialise the members of a class then you do it in the class initialisation list.

The initialisation list is something that can only be attached to a constructor and it specifies how to initialise class members as well as base classes.

In your case something like

Expand|Select|Wrap|Line Numbers
  1. Outer::Outer() :
  2.   in2(10)
  3. {
  4. }
  5.  
in much the same way you initialise the C member of Inner
Jun 16 '10 #3

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

Similar topics

18
by: Matt | last post by:
I try to compare the default constructor in Java and C++. In C++, a default constructor has one of the two meansings 1) a constructor has ZERO parameter Student() { //etc... } 2) a...
8
by: Sam Kuehn | last post by:
How do I accomplish the fallowing (is it even possible). Say I write a UserControl "MyControl.ascx". Now I use LoadControl("MyControl.ascx"). But I really want MyControl to require parameters in...
19
by: Andrew J. Marshall | last post by:
I want to create a class that must receive a parameter when instantiated. In other words, I do not want it to have a "Public Sub New()". 1) Does VB.NET create a default public constructor if I do...
3
by: SammyBar | last post by:
I'm trying to inherit from a Generic class but I'm having troubles on the syntax on how to specify a base constructor for my default constructor. I want to do something like this: public class...
1
by: Craig Buchanan | last post by:
is there an implicitly-defined Parent property defined for a class that is nested in another class? i'm looking to simplify my coding. At this point, i've defined the class as so: Class Item...
74
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
6
by: Mark | last post by:
I have a problem with a template class defined: // start matrix.h file template <class Tclass Matrix { public: Matrix() { // default constructor } Matrix(const Subscript rows, const...
3
by: Rahul | last post by:
Hi Everyone, I have the following code and the compiler complains that there isn't any default constructor available, class C { private: C() {
10
by: Jason Doucette | last post by:
Situation: I have a simple struct that, say, holds a color (R, G, and B). I created my own constructors to ease its creation. As a result, I lose the default constructor. I dislike this, but...
2
by: John Doe | last post by:
Hi, I am trying to port some C class routines into C++. THe original functions are use to set/get properties of buttons inside a toolbar : // This function is used to set btton text //...
1
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.