gagajanice
asked on
what is the meaning of const at the end of the class member function
hi all,
I am not sure whether my title describe the problem correctly or not. Apologise if i have not.
I have a class called CustLoaderFactory which is derived from TargetFactory and ObjectCollector class.
eg
---
class CustLoaderFactory : public TargetFactory<TsfLoader>, ,public ObjectCollector<TsfLoader>
by the way, may i know what is the purpose of <TsfLoader> in above code?
then in both TargetFactory and ObjectCollector class, it declared the member function with a const at the end.
eg.
---
virtual int func1(char *a, const void *b) = 0;
what is the purpose of the const 0? And how do i declare it in my body program?
eg.
header file
-------------
class a : public b<TsfLoader>, ,public c<TsfLoader>
{
public:
virtual int func 1(char *1a, const void *1b) = 0;
};
body code
-------------
int a::func1(char *1a, const void *1b)
{
strcpy(1a, (char *)1b);
return 0;
}
So, how do i call the func1 from my body code since it has a const at the back.
Beside that, since class a derive from class b and class c. by writing my own definition in body code for func1, am i overiding the original definition?
I am testing out some sample code to get more understanding on the c++ OOP.
Thank you in advance.
I am not sure whether my title describe the problem correctly or not. Apologise if i have not.
I have a class called CustLoaderFactory which is derived from TargetFactory and ObjectCollector class.
eg
---
class CustLoaderFactory : public TargetFactory<TsfLoader>, ,public ObjectCollector<TsfLoader>
by the way, may i know what is the purpose of <TsfLoader> in above code?
then in both TargetFactory and ObjectCollector class, it declared the member function with a const at the end.
eg.
---
virtual int func1(char *a, const void *b) = 0;
what is the purpose of the const 0? And how do i declare it in my body program?
eg.
header file
-------------
class a : public b<TsfLoader>, ,public c<TsfLoader>
{
public:
virtual int func 1(char *1a, const void *1b) = 0;
};
body code
-------------
int a::func1(char *1a, const void *1b)
{
strcpy(1a, (char *)1b);
return 0;
}
So, how do i call the func1 from my body code since it has a const at the back.
Beside that, since class a derive from class b and class c. by writing my own definition in body code for func1, am i overiding the original definition?
I am testing out some sample code to get more understanding on the c++ OOP.
Thank you in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi,
the const that i have after the class member function is not a suffix const but a const integer:
virtual int func1(char *a, const void *b) = 0; (equal to integer "0").
Are they the same?
the const that i have after the class member function is not a suffix const but a const integer:
virtual int func1(char *a, const void *b) = 0; (equal to integer "0").
Are they the same?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Inclusion of a pure virtual function in a class makes that class abstract. FYI - an abstract class cannot be instantiated.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi all,
sorry for getting back to you all on this a bit late. this is because i am going through the link provided by you all yesterday.
actually, i was asking what is the purpose of having '= 0' at the back of the member function.
thanks phoffric for telling me is a special syntax of pure virtual function.
I somehow manage to compile my program with the guidance from you all.
Thank you very much. Have a nice day.
sorry for getting back to you all on this a bit late. this is because i am going through the link provided by you all yesterday.
actually, i was asking what is the purpose of having '= 0' at the back of the member function.
thanks phoffric for telling me is a special syntax of pure virtual function.
I somehow manage to compile my program with the guidance from you all.
Thank you very much. Have a nice day.
One big step towards C++ mastery :)
Good luck learning!
Good luck learning!
It's a template class so TsfLoader is the template parameter
http://www.parashift.com/c++-faq-lite/templates.html