The following code is invalid in C ++
struct Test { int x; int y; }; void function(Test A, int n = Ax) { ... }
because the Ax parameter defaults to A. Is there a way around this limitation? The reason I want to do this is as follows. I have a Vector class that is very close to std :: vector but has a allocator_ member that is responsible for allocating memory. My copy constructor has two options:
Vector(const Vector& A, Allocator& allocator) { ... }
Such copy constructors are allowed by the standard if the second parameter has a default value. But I want the default value for the dispenser to be A.allocator_, so I tried
Vector(const Vector& A, Allocator& allocator = A.allocator_) { ... }
Unfortunately, it is not valid C ++. Do any of you have a solution to this problem?
c ++ default-value
Insideloop
source share