How to explain ?

How to explain:
Cat::Cat( int Age):itsAge(Age){}

and

Template <class T>
Class Array
{ public:
   …// constructors
 …// operators
        Array& operator= (const array&);
        T& operator [] (int offset) { return pType[offset];}
      Private: T *pType;
wanggang22Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sys_ProgCommented:
=========
 How to explain:
Cat::Cat( int Age):itsAge(Age){}
==========

Explanation

The above code illustrates the definition of a Constructor of a Class called Cat.
The Constructor Initialiser List is used to initialse the class member variable  itsAge with the parameter -Age- to the constructor

-----------------------------------------------------


=============================================

Template <class T>
Class Array
{ public:
   …// constructors
 …// operators
        Array& operator= (const array&);
        T& operator [] (int offset) { return pType[offset];}
      Private: T *pType;

=============================================

Explanation

Class Array is a Template Class which is used to have a class which would let u create Array kind of object for any type [including user defined types]
It overloads certain operators like =, []

Operator = is overloaded to copy an existing Array kind of object into a new Array object

Operator [] is overloaded to assign a value to one of the locations of the Array Object
0
beavis_shenzhenCommented:
I dont know where your troule lies.

"Cat::Cat( int Age):itsAge(Age){}"

the codes define a constructor of  class cat.
the following would be more understandable

Cat::Cat(int Age)
{
   ..default constructor of itsaAge
    ...constructor of class of tsAge with parameter age.
    ...assign the new value to itsAge.
}
the differences betweent the two forms of constructors is that the latter call a default constructor of itsAge and cosume a  little longer cpu time.
0
MirkoLMVCommented:
Cat::Cat( int Age):itsAge(Age){}
This line is a definition of a constructor for the Cat class (I have met such classes in SAMS Teach Yourself C++ in 24 hours).
The empty body of the function shows that it does not do something particular, just create the new instance object of the Cat class.
Between the parameters list and the opening curly brace of the body there is an initialization list. Such lists are preceded by the colon Operator and comma-separated (not in such a case, since there is a single member). The itsAge(Age) construction has the same effect as itsAge = Age; more conventional statement: to the itsAge data member it is assigned the actual value of the Age formal parameter. The initialization list is credited with better performance than conventional initializations within the constructor body because it is less employed the activation record.

Template <class T>
Class Array
{ public:
   // constructors
 // operators
        Array& operator= (const array&);
        T& operator [] (int offset) { return pType[offset];}
      Private: T *pType;
This piece of code has a major problem: a part of the class is missing, and it could have some importace.
It is a template class, designed tp handle arrays with elements of any type. Arrays are unidimensional here. T is the type of the array elements (integer, character, structure, maybe even objects) and the system avoids the writing of similar code just for type-issued differences.
Array& operator= (const array&); line is actually the header of a special function called overloaded operator. Such overloads are done for providing a syntax similar to conventional operators for functions which are performing ressemblant actions on user-defined types (for example addition of an integer to an integer member of a structure).
In this case, it is the assignment of a whole array to another. The parameter is the source (reference to an array) and the keyword const is employed to limit the access just to read-only, thus avoiding any change of the actual parameter's value. The destination is the array to store the value returned by the operator. Here it seems to be error: the name of the unique parameter should start with a capital and thus avoid type mismatches when copying the values.
The line  T& operator [] (int offset) { return pType[offset];}  is an overloaded array subscript operator (indexing operator, usded for accessing the array for reading or writing). It is an in-line function, because repeating of a single statement affects less the performance than the conventional function call with the subsequent activation record.

Good luck !
 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MirkoLMVCommented:
I am glad that I was of a help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.