i thought that typedef was used to define synonyms for existing types. in that statement it seems that he is defining a pointer to a function that takes a reference to an item of treeitemtype, BUT WHERE DOES HE DEFINE THE SYNONYM HE WANTS TO USE?
2) also this does not make sense to me
virtualbool isEmpty() const;
what is that const doing back there, what does it mean? and i thought that you were suppose to type const in the beginning not the end.
1) The name of the function pointer in that case is "functionType". It's in a weird location (IMO).
2) It means the function is a const function, meaning that it doesn't modify the classes internal variables. In short, you can use it with a const version of the class.
@firedraco but i thought that for typedef the first parameter is the existing data type and the second one is the synonym.
also if "functionType" is supposed to be the name of the pointer, then how come he does:
virtualvoid preordertraverse(functionType visit)
so if functiontype is the name of the pointer, this how come he can do the above?
also is virtualbool isEmpty() const; same as virtualconstbool isEmpty();??/?
I don't what's unclear here, since you typedef the pointer to a function you can now use it by its name which is functionType instead of virtualvoid preordertraverse( void (*functionType) (TreeItemType& anItem) )
also is virtualbool isEmpty() const; same as virtualconstbool isEmpty();??/?
No. the second one says, isEmpty is a virtual function that takes no argument and it returns a constant boolean
@blackcoder41, it's tricky for me because i thought that typedef was used like this :typedef existing_type new_type_name
according to the tutorial on this site. however, it did not mention using type def with functions. nevertheless i just found an article about it and it's much more clear now.
about the const, i thought u had it type it before, not after?
does this mean i can do something likeint x = 15 const since constint x = 15 is legal?
does this mean i can do something like int x = 15 const since constint x = 15 is legal?No, Remember that 15 is a literal, since it is a literal then it is already a constant.