class method overloading question
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Guillaume
2016-2-12
编辑:Guillaume
2016-2-12
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 个评论
Guillaume
2016-2-12
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#)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Chebyshev 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!