mercredi 1 juillet 2015

implicit parameter in implicit conversion

#include <iostream>
using namespace std;

struct From{
    int i;
    From(){}
};

struct By{
    By(const From& f){}
};

struct To{
    To(const By& b){}
};

int main() {
    From f;
    To to = f;  // error: conversion from 'From' to non-scalar type 'To' requested
    return 0;
}

Is there any way to make this work without modifying By and To ? And also without creating a By object first to convert From

Aucun commentaire:

Enregistrer un commentaire