warum wird Funktion nicht gefunden



  • Ich bekomme diesen Fehler

    error: no matching function for call to 'QCurvePlot::setData(int, std::vector<double, std::allocator<double> >&, std::vector<double, std::allocator<double> >)'
    include\qwtplotext/QCurvePlot.h:51: note: candidates are: void QCurvePlot::setData(size_t, std::vector<double, std::allocator<double> >&)
    include\qwtplotext/QCurvePlot.h:52: note: void QCurvePlot::setData(size_t, std::vector<double, std::allocator<double> >&, int, size_t)
    include\qwtplotext/QCurvePlot.h:53: note: void QCurvePlot::setData(size_t, std::vector<double, std::allocator<double> >&, std::vector<double, std::allocator<double> >&, int, size_t)
    include\qwtplotext/QCurvePlot.h:54: note: void QCurvePlot::setData(size_t, std::vector<double, std::allocator<double> >&, std::vector<double, std::allocator<double> >&)
    include\qwtplotext/QCurvePlot.h:55: note: void QCurvePlot::setData(size_t, const double*, size_t)
    include\qwtplotext/QCurvePlot.h:56: note: void QCurvePlot::setData(size_t, const double*, int, size_t)
    include\qwtplotext/QCurvePlot.h:57: note: void QCurvePlot::setData(size_t, const double*, const double*, size_t)
    include\qwtplotext/QCurvePlot.h:58: note: void QCurvePlot::setData(size_t, const double*, const double*, int, size_t)

    bei diesem Code:

    vector<double> timeAmplitude = amplitude(pulse->time());
        ui->curvePlotTimeAmplitude->setData(1, pulse->timeAxis(), timeAmplitude);
        ui->curvePlotTimeAmplitude->setData(1, pulse->timeAxis(), amplitude(pulse->time()));
    

    Der Fehler tritt nur in der letzten Zeile auf. Aber wo ist der Unterschied zu der darüber? 'amplitude ist definiert als:

    std::vector<double> amplitude(const std::vector<std::complex<double> > & array)
    {
        std::vector<double> amplitude;
        amplitude.resize(array.size());
        for (size_t i = 0; i < amplitude.size(); ++i) {
            amplitude[i] = std::abs(array[i]);
        }
        return amplitude;
    }
    


  • Der Unterschied ist, dass das einmal ein temporäres Objekt ist. Die Funktion erwartet ihr Argument als nicht-const-Referenz. Temporäre Objekte können aber nur an const-Referenzen gebunden werden.



  • amplitude liefert ein temporäres Objekt. Ein solches kannst du nicht als eine "normale" Referenz (vextor<>&) übergeben, sondern nur an eine const-Referenz (const vector<>&) oder wenn das Objekt kopiert (vector<>) wird ( so eine Funktion sucht dein Compiler ). Beim ersten Funktionsaufruf wird ein vector auf dem Stack angelegt, den kann man dann als Referenz übergeben.

    Lars



  • EDIT: hat sich geklärt



  • error: no matching function for call to 'LaserPulse::interpolateFrequencyDataToWavelengthAxis(std::vector<double, std::allocator<double> >&, std::vector<double, std::allocator<double> >, std::vector<double, std::allocator<double> >&, std::vector<std::complex<double>, std::allocator<std::complex<double> > >&, double)'
    note: candidates are: void LaserPulse::interpolateFrequencyDataToWavelengthAxis(const std::vector<double, std::allocator<double> >&, const std::vector<double, std::allocator<double> >&, const std::vector<double, std::allocator<double> >&, std::vector<double, std::allocator<double> >&, double)

    Du versuchst einen

    std::vector<std::complex<double>, std::allocator<std::complex<double> > >&
    

    in einen

    std::vector<double, std::allocator<double> >&
    

    zu stopfen ...



  • error: no matching function for call to
    
      LaserPulse::interpolateFrequencyDataToWavelengthAxis(
        std::vector<double>&,
        std::vector<double>,
        std::vector<double>&,
        std::vector<[b]std::complex<double>[/b]>&,
        double)
    
    note: candidates are:
    
      void
      LaserPulse::interpolateFrequencyDataToWavelengthAxis(
        const std::vector<double>&,
        const std::vector<double>&,
        const std::vector<double>&,
        std::vector<[b]double[/b]>&,
        double)
    

Anmelden zum Antworten