Need your help to explain this OOP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
_v3signal *_v3main :: find_v3_signal_bylhs ( char *s )
{
printf("chunhaun:lhs1,%s,%d\n",s,_num_v3_signals);
	if(!s){
printf("chunhaun:checklhs\n");
		return NULL;
	}

	for (int i = 0; i < _num_v3_signals; i++)
	{
		if (!strcmp (_V3Signals[i]->get_lhs (), s)){
cout << "chunhaun:lhs3," << _V3Signals[i] <<endl;
			return _V3Signals[i];
		}
	}
printf("chunhaun:lhsreturn\n");
	return NULL;
}



May I know when return _V3Signals[i];,what is the content actually stored inside _V3Signals[i]? What chapter should I study to know more on this?I am confuse.

For simple example:
int Class::add(a,b)
{
return a+b
}



I will know that the return content will be an integer value.But for the code above _v3signal *_v3main :: find_v3_signal_bylhs ( char *s )
So i dont know what actually will be return and stored inside _V3Signals[i];
There is a syntax for a function prototype, which is:
<return type> <function name>(<parameters>);
So in the code above, the function would be returning a pointer to _v3signal.

More info: http://cplusplus.com/doc/tutorial/functions/

Aceix.
Last edited on
Furthermore, the _V3Signals must have been declared somewhere. Perhaps in description of class _v3main? (_V3Signals[i] does not need to be _v3signal * as long as it is convertible to that type.)

Btw, line 3 is in wrong place. It does use s. s could be null. Only after the if-clause on lines 4-7 does one know that s is not null and can be used.

Also note that prefix and suffix underscores on names might cause trouble, because some compilers use them in their internal implementation.
Topic archived. No new replies allowed.