473,796 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::MYF UNCTION(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::MYF UNCTION: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 1683
kackson wrote:
Hi.
What does it mean when it is written as:
.....
What I dont understand is the meaning of the test.cpp ->
MYFUNCTION::MYF UNCTION: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(i nt x, int y, int z.. and some more argument);
... and some more other variables and functions...;
}

and then in the test.cpp file->

MYFUNCTION::MY FUNCTION(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::MY FUNCTION: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 "initializa tion 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*******@pres by.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.goo gle.com
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::MYF UNCTION(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::MYF UNCTION: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
3082
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 book which isn't aimed at people coming from C/Pascal/Java/Delpi/whatever... However, there seem to be plenty such books for all those other languages. Is there really no literature for people trying to learn programming by starting with C++? ...
15
1935
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 myprog2.cpp: In method `Line::Line (Point, Point)': myprog2.cpp:32: no matching function for call to `Point::Point ()'
8
2012
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 msg that im getting: "Error executing cl.exe" this is the code that I have, but I know whats causing it, ill just show you the whole thing first though //file: Quadratic
1
2627
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 experimenting a bit with what I need to do this and have the following code snippet. But first if I pass the assembly name and type to Activator.CreateInstance() it always fails. However if I walk my assembly and get a type value, the call to...
10
317
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 headers & structure definition). it's very handy to use "new SCRIPT_ITEM;" however I want to handle OutOfMemory gracefully, that is dealloc everything 1st and then throw a managed exception, I also
6
3010
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 interface is providing a convenient scripting toolkit for the application. One example is that a user can write a python script like: player = Player() game.loadPlayer(player) player.moveTo(location)
4
2815
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. I pretty much have most things under control and have set it up as follows: Form 1 Contains a DataGridView where users enter in information includeing the length of each round, small blind & big blind (its for
6
1366
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 will contain the name of the team as well as the country of the team and qualifying group ✔ Pot – This class will contain 8 instances of the class team ✔ DrawEngine – This class will contain the main draw strategy. In our case it will contain the...
4
2024
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 functions that offer conversions instead of conversion operators. In page 87, example 2: Errors that work. class String { // ...
22
18154
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 programmer and looking for a starting point in regards to practical projects to work on. What are some projects that beginner programmers usually start with? Please list a few that would be good for a beginner PHP programmer to
0
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.