3 small question in C++

1.
1
2
3
4
5
6
template<typename T> 
Interval<T>::Interval() 
{ 
a = T();
b = T(); 
}

what does T() mean?


2. the usually used name:
1)in copy structure, I saw many examples use rhs,like classname(const classname & rhs), what does rhs refer?
2)in class private member, we usually name our variable with prefix m, what does m mean??


3.
1
2
3
char * c;
int a;
c = a = 0;	// is this right?? why 
T is the template type. If you don't know about templates, you should learn about them. They're easy in principle.

T() calls the default constructor.

rhs means right-hand-side. For example:
 
a = b;
a is the right hand side, b is the left hand side.

m would indicate member

Chained assignments are ok, but as you're mixing types, I would say it's wrong.
1) T() means zero-initialization. It corresponds to call of the default consttructor of type T. If to return to your example if a and b would have type int we could write

a = 0;
b = 0;

Now let assume that T denotes some structure type for example struct A { char s[10[; }; and a and b are objects of this type that is a and b have declarations

T a;
T b;

that corresponds to

struct A a;
struct A b;

So we cannot write

struct A a = 0;
or
struct A b = 0;

because there is no such operations as assigning struct A to 0. So a common record T() is used that means calling of a default constructor.
If a and b are declared haveing the type int then it will look like

a = int();
b = int();

which means zero initialization. a and b will be initialized with 0.

2) rhs means right-hand side and denotes the right operand of a binary operation.

3) prefix m is abbreviation of the word member.

4) this expression c = a = 0; is incorrect. You may not an object of type int assign to a pointer. It would be correctly to write

c = reinterpret_cast<char *>( a = 0 );





Last edited on
kbw wrote:
rhs means right-hand-side. For example:
a = b;
a is the right hand side, b is the left hand side.
Listen, I know you're not sitting in front of my computer screen like I am, but you don't have to take that literally.
Last edited on
This may be shocking, but the equals sign doesn't have hands.

In all seriousness, in the expression a=b, a is the left hand operand. This is reflected in the terms l-value, which denotes expressions that can be assigned to (can appear on the left hand side of =).
I like to put 'o' (as "other") instead 'rhs'.
Topic archived. No new replies allowed.