c++ - Explicitly passing a const object to an constructor which takes const reference to a polymorphic class -
I found a problem with my classes, a clear constructor to pass a const object (multiform structure) A reference refers to the sample class for the base class of that polymorphic structure (this is not from my code, it is for clarification)
class base {...} Category derivative: Public base {...} class problem {problem (cost base & amp;;); ...} myFunction Zero (const problem and problem) {...} int main () {// explicit producer derived with non-intact objects; Problem number 1 (d); // This is working fine myFunction (no1); // Build constructor problem with const object no2 = derived (); // It is working fine, debugged and everything is called myFunction (no2); // working fine. Constant constructor working with Const object is not working Problem no 3 (Derived ()); // debugger jumps on this line (no compiler error) myFunction (no3); // This line does not say at all: // There is no match for calling your function (problem (& amp;) (derivative)) / Note: Candidates are: Muneefation (Const Dam & amp; }}
It seems that this is working fine with other versions (the obvious creator call for the problem), if I explicitly put the derived object in its base class base Is, like this:
problem (* (base *) & amp; Yutpnn);
I do not realize the difference in calling the problem class clearly constructively. Thanks!
The problem is that you are not declaring any object, but a function:
Problem No 3 (Generated ()); // equivalent: problem no 3 (derivative); Use
left with the parameter name:
problem no 3 ((derived ()); // Additional command to stop the work-declaration interpretation / which is otherwise required by the standard (so that the code is not ambiguous)
This announcement of C is a secret of the syntax, which is C ++.
More examples:
zero F (int (a)); / * Similarly: * / zero F (int a); Zero g () {zero function (int); // declared function zero function (int ()); // We can declare it again zero function (int = 42); // Add default value function (); // call: function (42) ('function' in the global radius) // 'function' is not available here (not declared) void function (int) {} // Definition for declarations
Comments
Post a Comment