473,805 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Could someone explain some code?

Can anyone explain what the lines with the '*' by them do?

-----------

#ifndef _COUNTER_H
#define _COUNTER_H
#include <iostream>
using namespace std;

class Counter
{
public:
int count;
public:
* Counter(){count = 0;}
void operator ++() { ++count; }
int GetCount() { return count; }
void SetCount( int c ) { count = c; }
void PrintCount() { cout << "\n The count is " << count; }

};

class NewCounter:publ ic Counter
{
public:
* void operator --() { --count; }
};

#endif
Jul 22 '05 #1
21 1649
Gactimus wrote:
Can anyone explain what the lines with the '*' by them do?

-----------

#ifndef _COUNTER_H
#define _COUNTER_H
Lose the leading underscore on that macro name.
#include <iostream>
using namespace std;
This is a very bad idea. Try to avoid ever putting 'using' directives
in a header.

class Counter
{
public:
int count;
public:
* Counter(){count = 0;}
This one declares and defines the default constructor for this class.
void operator ++() { ++count; }
int GetCount() { return count; }
void SetCount( int c ) { count = c; }
void PrintCount() { cout << "\n The count is " << count; }

};

class NewCounter:publ ic Counter
{
public:
* void operator --() { --count; }
This one declares and defines a pre-decrement operator for 'NewCounter'
};

#endif


V
Jul 22 '05 #2
Victor Bazarov <v.********@com Acast.net> wrote in
news:Gi******** *********@newsr ead1.dllstx09.u s.to.verio.net:
Gactimus wrote:
Can anyone explain what the lines with the '*' by them do?

-----------

#ifndef _COUNTER_H
#define _COUNTER_H


Lose the leading underscore on that macro name.
#include <iostream>
using namespace std;


This is a very bad idea. Try to avoid ever putting 'using' directives
in a header.

class Counter
{
public:
int count;
public:
* Counter(){count = 0;}


This one declares and defines the default constructor for this class.
void operator ++() { ++count; }
int GetCount() { return count; }
void SetCount( int c ) { count = c; }
void PrintCount() { cout << "\n The count is " << count;
}

};

class NewCounter:publ ic Counter
{
public:
* void operator --() { --count; }


This one declares and defines a pre-decrement operator for 'NewCounter'


Thank you.
Jul 22 '05 #3
Gactimus wrote:
[code help snipped]

You should get yourself a copy of "Accelrated C++"
by Koenig and Moo. Get yourself on the right path
early in your C++ studies. After you've got through
that, you should sample the books with good reviews
at www.accu.org.
Socks

Jul 22 '05 #4

"Gactimus" <ga******@xrs.n et> schrieb im Newsbeitrag
news:1102605878 .0eb1675083e856 48bb700b5e41f13 861@bubbanews.. .
Can anyone explain what the lines with the '*' by them do?

-----------

#ifndef _COUNTER_H
#define _COUNTER_H
#include <iostream>
using namespace std;

class Counter
{
public:
int count;
public:
* Counter(){count = 0;}

That is the Constructor - look in a C++ manual - any C++ manual
void operator ++() { ++count; }
int GetCount() { return count; }
void SetCount( int c ) { count = c; }
void PrintCount() { cout << "\n The count is " << count; }

};

class NewCounter:publ ic Counter
{
public:
* void operator --() { --count; }


that is the -- operator for the class NewCounter:
NewCounter cnt;
--cnt; // This will call it

Again, RTFM
-Gernot
Jul 22 '05 #5
"Gernot Frisch" <Me@Privacy.net > wrote in
news:31******** *****@individua l.net:
"Gactimus" <ga******@xrs.n et> schrieb im Newsbeitrag
news:1102605878 .0eb1675083e856 48bb700b5e41f13 861@bubbanews.. .
Can anyone explain what the lines with the '*' by them do?

-----------

#ifndef _COUNTER_H
#define _COUNTER_H
#include <iostream>
using namespace std;

class Counter
{
public:
int count;
public:
* Counter(){count = 0;}

That is the Constructor - look in a C++ manual - any C++ manual
void operator ++() { ++count; }
int GetCount() { return count; }
void SetCount( int c ) { count = c; }
void PrintCount() { cout << "\n The count is " << count; }

};

class NewCounter:publ ic Counter
{
public:
* void operator --() { --count; }


that is the -- operator for the class NewCounter:
NewCounter cnt;
--cnt; // This will call it


Ok in these lines:

void operator --() { --count; }
Counter(){count = 0;}
void operator ++() { ++count; }
int GetCount() { return count; }
void SetCount( int c ) { count = c; }
void PrintCount() { cout << "\n The count is " << count; }

What is the stuff in the {} brackets? What is it called? The book I have is
kind of crappy and I can't find where it discusses this.
Jul 22 '05 #6
Gactimus wrote:
Ok in these lines:

void operator --() { --count; }
Counter(){count = 0;}
void operator ++() { ++count; }
int GetCount() { return count; }
void SetCount( int c ) { count = c; }
void PrintCount() { cout << "\n The count is " << count; }

What is the stuff in the {} brackets? What is it called? The book I have is
kind of crappy and I can't find where it discusses this.


It's called "the body of the function".
Jul 22 '05 #7
Victor Bazarov <v.********@com Acast.net> wrote in
news:3r******** *********@newsr ead1.dllstx09.u s.to.verio.net:
Gactimus wrote:
Ok in these lines:

void operator --() { --count; }
Counter(){count = 0;}
void operator ++() { ++count; }
int GetCount() { return count; }
void SetCount( int c ) { count = c; }
void PrintCount() { cout << "\n The count is " << count; }

What is the stuff in the {} brackets? What is it called? The book I
have is kind of crappy and I can't find where it discusses this.


It's called "the body of the function".


So is it just a more efficient way of writing a function instead of
writing a prototype and a seperate body?
Jul 22 '05 #8
Gactimus <ga******@xrs.n et> wrote in
news:1102623238 .bb85af6c6bc249 3985259870e2129 90a@bubbanews:
Victor Bazarov <v.********@com Acast.net> wrote in
news:3r******** *********@newsr ead1.dllstx09.u s.to.verio.net:
Gactimus wrote:
Ok in these lines:

void operator --() { --count; }
Counter(){count = 0;}
void operator ++() { ++count; }
int GetCount() { return count; }
void SetCount( int c ) { count = c; }
void PrintCount() { cout << "\n The count is " << count; }

What is the stuff in the {} brackets? What is it called? The book I
have is kind of crappy and I can't find where it discusses this.


It's called "the body of the function".


So is it just a more efficient way of writing a function instead of
writing a prototype and a seperate body?


Actually, I think I see now.
Jul 22 '05 #9
> > #include <iostream>
using namespace std;


This is a very bad idea. Try to avoid ever putting 'using' directives
in a header.

Isn't that the standard? It's at least being taught as such...

Frank
Jul 22 '05 #10

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

Similar topics

13
2472
by: C++fan | last post by:
The following code is for list operation. But I can not understand. Could anyone explain the code for me? /* * List definitions. */ #define LIST_HEAD(name, type) struct name { type *lh_first; /* first element */
3
1588
by: MarcJessome | last post by:
Hi, I was wondering if someone could help me through learning C++. I've tried learning before, but I find I would work better if I had someone that could help explain a few things to me. Im using Bruce Eckel's Thinking in C++, but I have used others before. I use msn, icq and aim if its possible for someone to help me on an instant messenger. Thanks, Marc
5
2805
by: J Allen Horner | last post by:
I'm just starting to learn C, and the tutorial I'm reading uses this code as an example: ----------- #include <stdio.h> #define MAX 10 int a; int rand_seed=10;
4
15490
by: konsu | last post by:
hello, my client code communicates with a web service through a https connection. the code has a stub derived from SoapHttpClientProtocol. It also sets a certificate policy handler that allows everything: class CertificatePolicy : ICertificatePolicy { public bool CheckValidationResult(ServicePoint servicepoint, X509Certificate certificate, WebRequest request, int problem) { return
12
1698
by: you | last post by:
I may be just stupid, but I don't understand the point of using an Interface. I am going through a couple of books at the moment trying to teach myself a little vb.net. Just for the heck of it, ya know. Kinda interesting stuff. Anyhoo; Both of these talk about what an interface is, give an example, and then happily go on their merry way leaving me to guess as to WHY you would create and use one?
8
1655
by: Bart | last post by:
Could someone explain me what is wrong with this code ? I gives me a compile error: Error 1 Use of unassigned local variable 'fileStreamObject' C:\Documents and Settings\Bart\Local Settings\Application Data\Temporary Projects\WindowsApplication1\employeeReader.cs 22 17 WindowsApplication1 The code is:
2
9820
by: patrice.pare | last post by:
Hello, Here is a summary of my Dev Environment: I use Visual Studio 2005 Team Suite SP1 with Crystal Report XI SP1 on a Windows XP SP2 development workstation. I also use SQL Server 2000 SP4. And here a summary of what is the problem: I have a web application that has a web form into which I read data from a SQL database and load them in a ReportDocument of Crystal
12
1646
by: Tom | last post by:
First, my thanks in advance to those who can help explain away this mystery line of code. Petzold is a great teacher and I appreciate his work; however, his explanation about an extra line of code needed when a class is contained in a library vs the class being defined in a separate file within the project falls short of my ability to understand. Note: I've included the code (4 files) at the bottom, making this a long winded posting;...
6
1217
by: Dave Young | last post by:
I'm looking at some code that i've inherited and I'm not really familar with what's going on here and was hoping somone could explain it to me. For reference: f1 is a long f2 is a long here's the statement
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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
10356
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10103
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
6874
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
5536
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
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4316
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
3006
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.