as the title says I am curious if delegation constructor can be called in the body or not.
If you are curious about motivation: I have some condition and only workaround I found requires having uselss write on dummy member that occupies space.
#include <iostream>
using namespace std;
struct Delegating {
Delegating (const string& str) {
cout <<"const string& \n";
}
Delegating(string&& str): dummy_(str.size()>4 ? 0 : (Delegating(str),0)) {
if (str.size()>4) {
cout <<"string&& \n";
}
}
bool dummy_;
};
int main() {
// your code goes here
Delegating("abc");
Delegating("abcde");
Delegating("abcde");
Delegating("abcde");
Delegating("abc");
cout << "\n--------------------\n";
Delegating(string("abc"));
Delegating(string("abcde"));
Delegating(string("abcde"));
Delegating(string("abcde"));
Delegating(string("abcde"));
Delegating(string("abc"));
return 0;
}
Aucun commentaire:
Enregistrer un commentaire