Ok so I'm learning so much every day and trying to remember it all is difficult, I'm sure I've seen some info about this somewhere but I cant find any definitive explanations about the following query;
// What is the difference of where all these const/pointers are??
typedefint(*tfunc)(int);
typedefconstint(*tfunc)(int);
typedefint(* const tfunc)(int);
typedefint(*tfunc)(constint);
typedefint(tfunc)(int) const;
typedefint(const tfunc)(int);
typedefconstint(const tfunc)(constint);
class A {};
constclass A {};
class A {} const;
class A {
constint i;
intconst i;
constintconst i;
int func1(int i);
constint func2(int i);
tfunc * const func3(int i);
tfunc const * func4(int i);
const tfunc const * const func4(constint i) const; // ????? mind blown
};
If anyone ahs the time I would love each line to be commented with a specific explanation of what each pointer/const combination would mean.
I could guess a few of them, and know that const at end of func decl means that method doesn't change the state of its own instance or change any members?
I guess the const at the start (before retn type decl) would mean the returned value is immutable?
Anyway I would just love to have a definitive "cheat sheet" so to speak, so I can easily revise and hopefully stick to my flaky memory :).
// What is the difference of where all these const/pointers are??
typedefint(*tfunc)(int); // 1. Says tFunc-type value must be a pointer
typedefconstint(*tfunc)(int); // 2. Says return var is constant
typedefint(*const tfunc)(int); // 3. Says the pointer (pointing to tFunc-type obj) is const
typedefint(*tfunc)(constint); // 4. Says the parameter is const
typedefint(tfunc)(int) const; // 5. for methods? Says this method cannot modify the state of the object (also tFunc is value-type now? Does this actually make a difference?)
typedefint(const tfunc)(int); // 6. tfunc itself is const (function cant be overidden?) tFunc-type value is not pointer?
typedefconstint(const tfunc)(constint); // 7. return is const, tfunc value is const, parameter is const
typedefconstintconst (const * const tfunc const)(constintconst) const; // 8. Some consts are redundant, can be written as 9:
typedefconstint(const * tfunc const)(constint) const; // 9. return/param/pointer and function is const, same as:
typedefintconst (*constconst tfunc)(intconst) const; // 10. same as 9
class A {}; // 11. normal class
constclass A {}; // 12. const class, class cannot be modified? Could do with a better exaplanation of this one.
class A {} const; // 13. same as 12 maybe? hmmmmm
class A {
constint i; // 14. i is const
intconst i; // 15. same as 14?
constintconst i; // 16. same again?
int func1(int i); // 17. standard method
constint func2(int i); // 18. return value is const
tfunc * const func3(int i); // 19. return value (pointer-type) is const
tfunc const * func4(int i); // 20. return value is const (pointer can be changed?)
const tfunc const * const func4(constint i) const; // 21. so this is basically below:
const tfunc const * func4(constint i) const; // 22. const return value, const pointer, const param and cannot change object state?
};
Is this right? Anyone have any more insight or more definite definitions of these use cases?