473,668 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"this" question

Dear all,

I used to use C++ programming language at all time but moved to C# and
Java. Few days ago, I restarted studying about C++ with a very
beginner's mind. I wrote a simple class and gcc couldn't compile the
class. Any hints that I'm missing?

Header File:

#ifndef __Calc_h__
#define __Calc_h__

class Calc
{
private:
int a;
int b;
public:
Calc();
Calc(int a, int b);

~Calc();

int plus();
int minus();
int multi();
int divide();
};

#endif

Source File:

#include "Calc.h"

Calc::Calc()
{
this.a = 0;
this.b = 0;
}

Calc::Calc(int a, int b)
{
this.a = a;
this.b = b;
}

Calc::~Calc()
{
this.a = 0;
this.b = 0;
}

int Calc::plus()
{
return this.a + this.b;
}

int Calc::minus()
{
return this.a - this.b;
}

int Calc::multi()
{
return this.a * this.b;
}

int Calc::divide()
{
if (this.b != 0)
{
return this.a / this.b;
}
else if (a != 0)
{
return this.b / this.a;
}
else
{
return 0;
}
}
GCC command:

$gcc Calc.cpp -lstdc++

Error Message:

Calc.cpp: In constructor 'Calc::Calc()':
Calc.cpp:6: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:7: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In constructor 'Calc::Calc(int , int)':
Calc.cpp:12: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:13: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In destructor 'Calc::~Calc()' :
Calc.cpp:18: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:19: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::plus()':
Calc.cpp:24: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:24: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::minus()':
Calc.cpp:29: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:29: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::multi()':
Calc.cpp:34: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:34: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::divide()' :
Calc.cpp:39: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:41: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:41: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:45: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:45: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'

I think those error messages mean 'a' and 'b' are not members of Calc
class. Why is that?

Thanks,

Sep 20 '07 #1
14 2113
Alexander Dong Back Kim wrote:
Dear all,

I used to use C++ programming language at all time but moved to C# and
Java. Few days ago, I restarted studying about C++ with a very
beginner's mind. I wrote a simple class and gcc couldn't compile the
class. Any hints that I'm missing?
Look at the compiler message. "this" is of type Calc* const, notably a
pointer. Where you have "this." you should have "this->". But "should"
is the wrong word here since you don't need to use "this" at all here.
Rather than "this->a = 0" simply write "a = 0".
>
Header File:

#ifndef __Calc_h__
#define __Calc_h__

class Calc
{
private:
int a;
int b;
public:
Calc();
Calc(int a, int b);

~Calc();

int plus();
int minus();
int multi();
int divide();
};

#endif

Source File:

#include "Calc.h"

Calc::Calc()
{
this.a = 0;
this.b = 0;
}

Calc::Calc(int a, int b)
{
this.a = a;
this.b = b;
}

Calc::~Calc()
{
this.a = 0;
this.b = 0;
}

int Calc::plus()
{
return this.a + this.b;
}

int Calc::minus()
{
return this.a - this.b;
}

int Calc::multi()
{
return this.a * this.b;
}

int Calc::divide()
{
if (this.b != 0)
{
return this.a / this.b;
}
else if (a != 0)
{
return this.b / this.a;
}
else
{
return 0;
}
}
GCC command:

$gcc Calc.cpp -lstdc++

Error Message:

Calc.cpp: In constructor 'Calc::Calc()':
Calc.cpp:6: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:7: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In constructor 'Calc::Calc(int , int)':
Calc.cpp:12: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:13: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In destructor 'Calc::~Calc()' :
Calc.cpp:18: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:19: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::plus()':
Calc.cpp:24: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:24: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::minus()':
Calc.cpp:29: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:29: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::multi()':
Calc.cpp:34: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:34: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::divide()' :
Calc.cpp:39: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:41: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:41: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:45: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:45: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'

I think those error messages mean 'a' and 'b' are not members of Calc
class. Why is that?

Thanks,
Sep 20 '07 #2
Alexander Dong Back Kim wrote:
Dear all,

I used to use C++ programming language at all time but moved to C# and
Java. Few days ago, I restarted studying about C++ with a very
beginner's mind. I wrote a simple class and gcc couldn't compile the
class. Any hints that I'm missing?

Header File:

#ifndef __Calc_h__
#define __Calc_h__
Other than the fact that "this" is a pointer, and you should use
"this->" instead of "this.", or just drop the "this" completely, your
include guard is also incorrect.

ISO/IEC 14882:2003 17.4.3.1.2/1 specifies that identifiers containing a
double underscore are reserved to the implementation. Also, don't
change it to _Calc_h_, since identifiers with a leading underscore
followed by an uppercase letter are reserved to the implementation in
the global namespace.

class Calc
{
private:
int a;
int b;
public:
Calc();
Calc(int a, int b);

~Calc();

int plus();
int minus();
int multi();
int divide();
};

#endif

Source File:

#include "Calc.h"

Calc::Calc()
{
this.a = 0;
this.b = 0;
}

Calc::Calc(int a, int b)
{
this.a = a;
this.b = b;
}

Calc::~Calc()
{
this.a = 0;
this.b = 0;
}

int Calc::plus()
{
return this.a + this.b;
}

int Calc::minus()
{
return this.a - this.b;
}

int Calc::multi()
{
return this.a * this.b;
}

int Calc::divide()
{
if (this.b != 0)
{
return this.a / this.b;
}
else if (a != 0)
{
return this.b / this.a;
}
else
{
return 0;
}
}
GCC command:

$gcc Calc.cpp -lstdc++

Error Message:

Calc.cpp: In constructor 'Calc::Calc()':
Calc.cpp:6: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:7: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In constructor 'Calc::Calc(int , int)':
Calc.cpp:12: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:13: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In destructor 'Calc::~Calc()' :
Calc.cpp:18: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:19: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::plus()':
Calc.cpp:24: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:24: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::minus()':
Calc.cpp:29: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:29: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::multi()':
Calc.cpp:34: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:34: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::divide()' :
Calc.cpp:39: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:41: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:41: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:45: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:45: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'

I think those error messages mean 'a' and 'b' are not members of Calc
class. Why is that?

Thanks,
Sep 20 '07 #3
On 9 21 , 7 51 , red floyd <no.s...@here.d udewrote:
Alexander Dong Back Kim wrote:
Dear all,
I used to use C++ programming language at all time but moved to C# and
Java. Few days ago, I restarted studying about C++ with a very
beginner's mind. I wrote a simple class and gcc couldn't compile the
class. Any hints that I'm missing?
Header File:
#ifndef __Calc_h__
#define __Calc_h__

Other than the fact that "this" is a pointer, and you should use
"this->" instead of "this.", or just drop the "this" completely, your
include guard is also incorrect.

ISO/IEC 14882:2003 17.4.3.1.2/1 specifies that identifiers containing a
double underscore are reserved to the implementation. Also, don't
change it to _Calc_h_, since identifiers with a leading underscore
followed by an uppercase letter are reserved to the implementation in
the global namespace.
class Calc
{
private:
int a;
int b;
public:
Calc();
Calc(int a, int b);
~Calc();
int plus();
int minus();
int multi();
int divide();
};
#endif
Source File:
#include "Calc.h"
Calc::Calc()
{
this.a = 0;
this.b = 0;
}
Calc::Calc(int a, int b)
{
this.a = a;
this.b = b;
}
Calc::~Calc()
{
this.a = 0;
this.b = 0;
}
int Calc::plus()
{
return this.a + this.b;
}
int Calc::minus()
{
return this.a - this.b;
}
int Calc::multi()
{
return this.a * this.b;
}
int Calc::divide()
{
if (this.b != 0)
{
return this.a / this.b;
}
else if (a != 0)
{
return this.b / this.a;
}
else
{
return 0;
}
}
GCC command:
$gcc Calc.cpp -lstdc++
Error Message:
Calc.cpp: In constructor 'Calc::Calc()':
Calc.cpp:6: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:7: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In constructor 'Calc::Calc(int , int)':
Calc.cpp:12: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:13: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In destructor 'Calc::~Calc()' :
Calc.cpp:18: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:19: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::plus()':
Calc.cpp:24: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:24: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::minus()':
Calc.cpp:29: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:29: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::multi()':
Calc.cpp:34: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:34: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::divide()' :
Calc.cpp:39: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:41: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:41: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:45: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:45: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
I think those error messages mean 'a' and 'b' are not members of Calc
class. Why is that?
Thanks,- -

- -
^_^, "this" is a pointer.

Sep 21 '07 #4
On Sep 21, 11:32 am, wxghust <wxgh...@gmail. comwrote:
On 9 21 , 7 51 , red floyd <no.s...@here.d udewrote:
Alexander Dong Back Kim wrote:
Dear all,
I used to use C++ programming language at all time but moved to C# and
Java. Few days ago, I restarted studying about C++ with a very
beginner's mind. I wrote a simple class and gcc couldn't compile the
class. Any hints that I'm missing?
Header File:
#ifndef __Calc_h__
#define __Calc_h__
Other than the fact that "this" is a pointer, and you should use
"this->" instead of "this.", or just drop the "this" completely, your
include guard is also incorrect.
ISO/IEC 14882:2003 17.4.3.1.2/1 specifies that identifiers containing a
double underscore are reserved to the implementation. Also, don't
change it to _Calc_h_, since identifiers with a leading underscore
followed by an uppercase letter are reserved to the implementation in
the global namespace.
class Calc
{
private:
int a;
int b;
public:
Calc();
Calc(int a, int b);
~Calc();
int plus();
int minus();
int multi();
int divide();
};
#endif
Source File:
#include "Calc.h"
Calc::Calc()
{
this.a = 0;
this.b = 0;
}
Calc::Calc(int a, int b)
{
this.a = a;
this.b = b;
}
Calc::~Calc()
{
this.a = 0;
this.b = 0;
}
int Calc::plus()
{
return this.a + this.b;
}
int Calc::minus()
{
return this.a - this.b;
}
int Calc::multi()
{
return this.a * this.b;
}
int Calc::divide()
{
if (this.b != 0)
{
return this.a / this.b;
}
else if (a != 0)
{
return this.b / this.a;
}
else
{
return 0;
}
}
GCC command:
$gcc Calc.cpp -lstdc++
Error Message:
Calc.cpp: In constructor 'Calc::Calc()':
Calc.cpp:6: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:7: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In constructor 'Calc::Calc(int , int)':
Calc.cpp:12: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:13: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In destructor 'Calc::~Calc()' :
Calc.cpp:18: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:19: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::plus()':
Calc.cpp:24: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:24: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::minus()':
Calc.cpp:29: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:29: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::multi()':
Calc.cpp:34: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:34: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::divide()' :
Calc.cpp:39: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:41: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:41: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:45: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:45: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
I think those error messages mean 'a' and 'b' are not members of Calc
class. Why is that?
Thanks,- -
- -

^_^, "this" is a pointer.
On Sep 21, 11:32 am, wxghust <wxgh...@gmail. comwrote:
On 9 21 , 7 51 , red floyd <no.s...@here.d udewrote:
Alexander Dong Back Kim wrote:
Dear all,
I used to use C++ programming language at all time but moved to C# and
Java. Few days ago, I restarted studying about C++ with a very
beginner's mind. I wrote a simple class and gcc couldn't compile the
class. Any hints that I'm missing?
Header File:
#ifndef __Calc_h__
#define __Calc_h__
Other than the fact that "this" is a pointer, and you should use
"this->" instead of "this.", or just drop the "this" completely, your
include guard is also incorrect.
ISO/IEC 14882:2003 17.4.3.1.2/1 specifies that identifiers containing a
double underscore are reserved to the implementation. Also, don't
change it to _Calc_h_, since identifiers with a leading underscore
followed by an uppercase letter are reserved to the implementation in
the global namespace.
class Calc
{
private:
int a;
int b;
public:
Calc();
Calc(int a, int b);
~Calc();
int plus();
int minus();
int multi();
int divide();
};
#endif
Source File:
#include "Calc.h"
Calc::Calc()
{
this.a = 0;
this.b = 0;
}
Calc::Calc(int a, int b)
{
this.a = a;
this.b = b;
}
Calc::~Calc()
{
this.a = 0;
this.b = 0;
}
int Calc::plus()
{
return this.a + this.b;
}
int Calc::minus()
{
return this.a - this.b;
}
int Calc::multi()
{
return this.a * this.b;
}
int Calc::divide()
{
if (this.b != 0)
{
return this.a / this.b;
}
else if (a != 0)
{
return this.b / this.a;
}
else
{
return 0;
}
}
GCC command:
$gcc Calc.cpp -lstdc++
Error Message:
Calc.cpp: In constructor 'Calc::Calc()':
Calc.cpp:6: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:7: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In constructor 'Calc::Calc(int , int)':
Calc.cpp:12: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:13: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In destructor 'Calc::~Calc()' :
Calc.cpp:18: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:19: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::plus()':
Calc.cpp:24: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:24: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::minus()':
Calc.cpp:29: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:29: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::multi()':
Calc.cpp:34: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:34: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp: In member function 'int Calc::divide()' :
Calc.cpp:39: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:41: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:41: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:45: error: request for member 'b' in 'this', which is of non-
class type 'Calc* const'
Calc.cpp:45: error: request for member 'a' in 'this', which is of non-
class type 'Calc* const'
I think those error messages mean 'a' and 'b' are not members of Calc
class. Why is that?
Thanks,- -
- -

^_^, "this" is a pointer.
Far out!!!

It seems I become really stupid because of C# and Java programming
languages which never use "->"!!! How can I possibly forget about "->"
operator!!! haha

Thanks guys who commented my question. =)

Thanks heaps,

Sep 21 '07 #5
Alf P. Steinbach wrote:
It's generally redundant and just visual clutter.
In the same way as using variable names longer than one character is
redundant and visual clutter?
Why comment your code either? It's just clutter.
Sep 21 '07 #6

Juha Nieminen wrote:
Alf P. Steinbach wrote:
It's generally redundant and just visual clutter.

In the same way as using variable names longer than one character is
redundant and visual clutter?
No, naming variables well conveys intent and purpose.
e.g:
If I call a <Carobject EmpireState and a building
object <Mercedes>, then it is certainly not going
to help the maintainer. That is why one character
is not used.

OTOH, if you write a class and you know the name
of the member is x (and especially if you follow some
convention, like suffixing the member with _, or prefixing
it with m_), then (<this->) really does become redundant,
and in fact, I've never come across code where people
used (this->) if they did not need to, except maybe
when writing templates, and they are in doubt of whether
the member in question is dependent on T.
Why comment your code either? It's just clutter.
As far as comments go, if you name your functions and
variables well (so that the names convey intent), the
code becomes self-commenting, and commenting is
hardly needed. This has been discussed many times
in the past.

Regards,

Werner

Sep 21 '07 #7
On Sep 21, 11:56 am, werasm <wer...@gmail.c omwrote:
Juha Nieminen wrote:
Alf P. Steinbach wrote:
It's generally redundant and just visual clutter.
In the same way as using variable names longer than one character is
redundant and visual clutter?

No, naming variables well conveys intent and purpose.
e.g:
If I call a <Carobject EmpireState and a building
object <Mercedes>, then it is certainly not going
to help the maintainer. That is why one character
is not used.

OTOH, if you write a class and you know the name
of the member is x (and especially if you follow some
convention, like suffixing the member with _, or prefixing
it with m_), then (<this->) really does become redundant,
and in fact, I've never come across code where people
used (this->) if they did not need to, except maybe
when writing templates, and they are in doubt of whether
the member in question is dependent on T.
Why comment your code either? It's just clutter.

As far as comments go, if you name your functions and
variables well (so that the names convey intent), the
code becomes self-commenting, and commenting is
hardly needed. This has been discussed many times
in the past.

Regards,

Werner
Ideas like that make my job that much harder. I'm constantly porting
old code to new code. Comments are crucial. Maybe not a comment for
every line of code, but perhaps something at the beginning of each
code item that is public (such as functions and classes). Trust me,
I'm not a guru in every business out there so sometimes I need
comments to explain a business rule or two.

Sep 21 '07 #8

GameboyHippo wrote:

Ideas like that make my job that much harder. I'm constantly porting
old code to new code. Comments are crucial. Maybe not a comment for
every line of code, but perhaps something at the beginning of each
code item that is public (such as functions and classes). Trust me,
I'm not a guru in every business out there so sometimes I need
comments to explain a business rule or two.
BTW, I'm sure your member functions are riddled with:

this->andThat;

c'mon, admit it. Do you really use (this->). is the point the
previous
poster made really valid?

Sep 21 '07 #9
werasm wrote:
As far as comments go, if you name your functions and
variables well (so that the names convey intent), the
code becomes self-commenting, and commenting is
hardly needed.
Personally I disagree with that. Comments are a good way
(even for the programmer itself) to visually separate logical
parts of the source code. When you later need to find a
specific part for whatever modification, good comments may
help you find it a lot faster than if there were no comments
at all.

Also it may not be immediately obvious what some part of the
code is doing from the variable names and code alone.

Personally I use this rule of thumb: If I coded something and
some time later I have to go back to that code and at some part
I have to stop for many seconds to try to remember what that part
is doing, I add the a comment explaining it when I do remember.
The rationale is: If to me, who created that code, it's not
immediately obvious what something is doing, it will be much
harder for someone else to understand it. Besides, it helps me
too, because in the future I don't have to once again try to
remember what something is doing.

Also if something uses a non-obvious technique or algorithm
I think it's good to explain it. Nothing is more irritating than
trying to reverse-engineer an ingenuous or complex algorithm from
someone else's source code, simply because he was too lazy to
explain it.
Sep 22 '07 #10

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

Similar topics

5
2777
by: Michael Stevens | last post by:
Probably the wrong wording but since I'm not a scripter I won't claim to know what I'm talking about. I got this script from www.htmlgoodies.com <script language="JavaScript"> <!-- window.open ('photos01.html','photogallery',config='height=550, width=750,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
3
4222
by: Hodad | last post by:
I would like to adapt, as much as possible, the appearance and color red of the font in this button: <P><CENTER><BUTTON VALUE="SUBMIT"><A HREF="http://www.familytreedna.com/surname_join.asp?code=Q17978" STYLE="TEXT-DECORATION: NONE;"> <FONT COLOR="RED" FACE="COPPERPLATE GOTHIC BOLD">Right Here</FONT></A></BUTTON></CENTER></P>
1
5662
by: Peter King | last post by:
if you assign multiple classes in order to keep your classes generic e.g ..classA { position.absolute; left:5 top:5 height:200 width:800 } ..classB { background-color: red} ..classC { background-color: green} <div id="div1" class="classA classB" ... but then want to dynamically assign a new class
9
2175
by: aden | last post by:
I have read the years-old threads on this topic, but I wanted to confirm what they suggest. . . Can the this pointer EVER point to a type different from the class that contains the member function that the this pointer is being used in? That is, is the type of the this pointer always determined entirely syntactically (and never dynamically)? Example: if a member function is invoked on an object of class Apple (appleobj.drip_it() ),...
7
1590
by: Daniel Ervi | last post by:
Hi All, I have a question for the group as I can't seem to come up with any suitable solutions. I'm not that new to programming or C#, but neither am I very fluent yet, so I'd appreciate any help at mastering my craft. What I am trying to do is best illustrated in code: public class TBase
6
5487
by: Thomas H | last post by:
Hi everyone, I've got a question that's more of a "style" question... Do you guys reference "this" for every object that's inherited from System.Web.UI.Page? For example, when you use the Session object, do you say "this.Session.property" or do you just say "Session.property", and leave off "this"? I'm tending towards always using "this.Session" and "this.Response" and "this.Label5.Text" - even though I don't have to. I have the...
7
2233
by: relient | last post by:
Question: Why can't you access a private inherited field from a base class in a derived class? I have a *theory* of how this works, of which, I'm not completely sure of but makes logical sense to me. So, I'm here for an answer (more of a confirmation), hopefully. First let me say that I know people keep saying; it doesn't work because the member "is a private". I believe there's more to it than just simply that... Theory: You inherit,...
5
588
by: WaterWalk | last post by:
Hello. The question about "deleting this inside the class's member function" is discussed many times in this group and in the "C++ FAQs". But I still have two more questions. 1. Take the following class as an example: class Test { public: static void print_message(char *s) { printf("%s\n", s); } void delete_me()
6
2321
by: babakandme | last post by:
Hi to every body...:D I'm a novice C++ programmer & I've a question, I have the ClassA & in it's constructor, I instantiate ClassB, and I want send "this" pointer """pointer to ClassA""" to the ClassB. But I get this Error from the compiler: and it's in ClassB... Error from the compiler: error C2061: syntax error : identifier 'TestA' error C2143: syntax error : missing ';' before '*'
0
8381
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
8893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8797
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...
1
8583
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8656
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
7401
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
6209
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
5681
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
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.