class method overloading question
1 view (last 30 days)
Show older comments
I have a handle class called DBHandle. I have a method runquery in it. I have a subclass SqlDBhandle in which I am not defining the method runquery explicitly.
Will an SqlDBHandle pick up the runquery from the DBHandle? I keep getting error: 'Too many input arguments'. Thanks.
jennifer
0 Comments
Answers (1)
Guillaume
on 12 Feb 2016
Edited: Guillaume
on 12 Feb 2016
The subclass automatically inherits all public and protected (but not private) methods of the baseclass. So, yes, as long as runquery is public or protected, SqlDBHandle will use the runquery method defined in DBHandle.
'Too many input arguments' does not sound like an error that has to do with inheritance. How are you calling runquery and how is it defined?
2 Comments
Guillaume
on 12 Feb 2016
Well, yes your call to runquery does not match the method signature. Note that in matlab this:
lkTbl = sqlDbHand.runquery(sSql);
is actually translated by matlab interpreted into
lkTbl = runquery(sqlDbHand, sSql);
You can see that you are actually passing two arguments to runquery. The object itself, and the sSql argument. Therefore, the signature or runquery should be:
function result = runquery(this, inSql)
result = ...
end
Note that I've changed the name of the return value from obj to something else. I'm not sure what you meant by obj, but if you meant the DBHandle class object, it's not an output, it's an input which I've called this (as that's the standard name in C++ and C#)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!