473,395 Members | 2,713 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,395 software developers and data experts.

Beginner C++ class problem

Hi.
What does it mean when it is written as:

in the test.hpp file->

class MYFUNCTION: public TOP
{
public:
....some variables...
MYFUNCTION(int x, int y, int z.. and some more argument);
.... and some more other variables and functions...;
}

and then in the test.cpp file->

MYFUNCTION::MYFUNCTION(int z, int y, int z,.. and some more
argument):TOP(x,y,z,w),_aa(a), _bb(b),_cc(c)
{
....some functions...;
}

What I dont understand is the meaning of the test.cpp ->
MYFUNCTION::MYFUNCTION:TOP(){}

What does this mean :: and follow by : and then a pair of {} means?
Could someone point me to a website where I could read such basic
things?

Thanks.
Jul 19 '05 #1
3 1658
kackson wrote:
Hi.
What does it mean when it is written as:
.....
What I dont understand is the meaning of the test.cpp ->
MYFUNCTION::MYFUNCTION:TOP(){}

What does this mean :: and follow by : and then a pair of {} means?
Could someone point me to a website where I could read such basic
things?


I think you're referring to the initializer list.

This is a simpler *compilable* example.

#include <iostream>

class B
{
public:
B( int );

int b;
};

class A : public B
{
public:

A( int );
};
A::A( int val )
: B( val ) // <<< initializer list
{
std::cout << "A is constructed\n";
}

B::B( int val )
: b( val ) // <<< initializer list
{
std::cout << "B is constructed\n";
}
A a( 2 );

int main()
{
}

The initializer list is only somthing you can place on a constructor.

Jul 19 '05 #2
In article <90**************************@posting.google.com >,
kackson <ka*****@yahoo.com> wrote:

in the test.hpp file->

class MYFUNCTION: public TOP
{
public:
...some variables...
MYFUNCTION(int x, int y, int z.. and some more argument);
... and some more other variables and functions...;
}

and then in the test.cpp file->

MYFUNCTION::MYFUNCTION(int z, int y, int z,.. and some more
argument):TOP(x,y,z,w),_aa(a), _bb(b),_cc(c)
{
...some functions...;
}

What I dont understand is the meaning of the test.cpp ->
MYFUNCTION::MYFUNCTION:TOP(){}

What does this mean ::
That's the "scope resolution operator." On its left is the name of a
class, and on the right is the name of a member function of that class.
You use this notation when you define a member function because different
classes can have member functions with the same name, so when you define a
member function, you have to say which class it belongs to.
and follow by :
This particular member function is the constructor for class
MYFUNCTION. (You can tell it's the constructor because it has the same
name as the class itself.) The list of things after the : is the
constructor's "initialization list." Basically it says, take the
arguments x,y,z,w and use them to initialize the member data of class TOP
(from which MYFUNCTION is derived), then take the argument a and use it to
initialize the member data _aa of MYFUNCTION, etc.
and then a pair of {} means?
If this constructor had any actual executable statements, they would go
between these braces, just like in any other function. In this particular
constructor, all the work is done in the initialization list, so it
doesn't need any executable statements, but you still have to have the
empty {} to keep the compiler happy.
Could someone point me to a website where I could read such basic
things?


Try a decent textbook instead. If you don't want to pay for a printed
book, I understand the free downloadable e-book "Thinking in C++" at
<http://www.bruceeckel.com/> is OK.

--
Jon Bell <jt*******@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
Jul 19 '05 #3
"kackson" <ka*****@yahoo.com> wrote in message
news:90**************************@posting.google.c om
Hi.
What does it mean when it is written as:

in the test.hpp file->

class MYFUNCTION: public TOP
{
public:
...some variables...
MYFUNCTION(int x, int y, int z.. and some more argument);
... and some more other variables and functions...;
}

and then in the test.cpp file->

MYFUNCTION::MYFUNCTION(int z, int y, int z,.. and some more
argument):TOP(x,y,z,w),_aa(a), _bb(b),_cc(c)
{
...some functions...;
}

What I dont understand is the meaning of the test.cpp ->
MYFUNCTION::MYFUNCTION:TOP(){}

What does this mean :: and follow by : and then a pair of {} means?
Could someone point me to a website where I could read such basic
things?

Thanks.


You need a book. This one can be downloaded for free:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html
--

John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Richard B. Kreckel | last post by:
Hi! I was recently asked what book to recommend for a beginner in C++. I am convinced that you needn't study C in depth before learning C++ (though it helps), but cannot find any beginner's...
15
by: PhilB | last post by:
Hello experts, I am a complete beginner in C++ (although I know C). I am trying to compile the code below, and I get the following error. Can anyone explain to me my mistake? Thanks! PhilB ...
8
by: Bshealey786 | last post by:
Okay im doing my final project for my first computer science class(its my major, so it will be my first of many), but anyway im a beginner so im not to great with C++ yet. Anyway this is the error...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
10
by: Lloyd Dupont | last post by:
how do I redefine the new operator? for all the structure I use at once! (some of them comes from C include files). The rationale: I'm writting a managed C++ wrapper around C API (external...
6
by: Qun Cao | last post by:
Hi Everyone, I am a beginner on cross language development. My problem at hand is to build a python interface for a C++ application built on top of a 3D game engine. The purpose of this python...
4
by: Bails | last post by:
Hi Im an absolute beginner in programming and am using VB.Net Express. To start my larning I decided to do a "Real World" app instead of "hello world" and am creating a Poker Countdown clock. ...
6
by: sugard | last post by:
I am a java beginner and as a task I was given to implement a champions league second phase draws. The program that I am going to implement must contain the following classes: Team – This class...
4
by: subramanian100in | last post by:
In the book, C++ Coding Standards book by Hereb Sutter and Andrei Alexandrescu, in Item 40 on pages 86-87 viz, "Avoid providing implicit conversions", the authors have advised the use of named...
22
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php...
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
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.