dump - Segmentation Fault C++, after parentheses operator -
i have class override parentheses operator. following code works:
int main(){ .. a; cout << a({0.5}); .. }
while following code doesn't work
a fun(){ .. a; return a; .. } int main(){ .. a = fun(); cout << a({0.5}); }
when execute second code, have following error:
segmentation fault (core dumped)
i can't understand why.
edit:
this overriding of operator:
virtual arma::vec operator()(const inputc& input) override { const arma::vec& x = params.normalizationf->normalize(base::phi(input)); forwardcomputation(x); return params.normalizationo->restore(h.back()); }
this constructor:
ffneuralnetwork_(features_<inputc, denseoutput>& phi, unsigned int neurons, unsigned int outputs) : parametricregressor(phi, outputs), batchregressor_<inputc, arma::vec, denseoutput>(phi, outputs) { layerfunction.push_back(new sigmoid()); layerfunction.push_back(new linear()); layerneurons.push_back(neurons); layerneurons.push_back(outputs); setupnetwork(); }
and actually:
typedef ffneuralnetwork_<arma::vec> ffneuralnetwork;
where ffneuralnetwork class used in example.
here actual working code:
basisfunctions basisplane_ = identitybasis::generate(1); densefeatures phiplane_(basisplane_); ffneuralnetwork planenet(phiplane_, 10, 1); cout << planenet({0.5});
here not working code:
ffneuralnetwork createnetwork(..){ basisfunctions basisplane_ = identitybasis::generate(1); densefeatures phiplane_(basisplane_); ffneuralnetwork planenet(phiplane_, 10, 1); return planenet; } .. ffneuralnetwork net = createnetwork(..); cout << net({0.5});
in bit of code you're passing local variable phiplane_
reference:
ffneuralnetwork createnetwork(..){ basisfunctions basisplane_ = identitybasis::generate(1); densefeatures phiplane_(basisplane_); ffneuralnetwork planenet(phiplane_, 10, 1); // <- here return planenet; } ffneuralnetwork net = createnetwork(..); cout << net({0.5});
once function returns object passed reference no longer exists no code should access after that. may or may not ok depending on happens in parametricregressor(phi, outputs)
, seems bit dubious me , explain problem.
Comments
Post a Comment