#beginner: no default constructor exists for class

19 messages · Page 1 of 1 (latest)

tight nacelle
#

I don't know why but this is returning a no default constructor error. Just yesterday, it was working fine but now it's not.


class statistical_distribution {
public:
    std::vector<float> distribution;
    float mean_val;
    float standard_deviation_val;


    statistical_distribution(std::vector<float> x)
    {
        std::cout << "Constructing distribution\n";

        distribution = x;
        mean_val = mean(x);
        standard_deviation_val = standard_deviation(x);

    };

    virtual ~statistical_distribution() {
        std::cout << "Deconstructing distribution\n";
    };

    // Mean and Summation Formula

    std::tuple<float, size_t> summation(std::vector<float> i_vector) {...}

    float mean(std::vector<float> i_vector, bool sample = false) {...}

    // Standard deviation + Variance

    float variance(std::vector<float> i_vector, bool sample = false) {...}

    float standard_deviation(std::vector<float> i_vector) {...}

};


int main()
{
    std::vector<float> test_1 = {1,2,3,4,5,6,7,8,9,10};
    
    // error is here
    statistical_distribution(test_1);

    return 0;
}

static chasmBOT
#

When your question is answered use !solved or the button below to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

wise musk
#

Your "construction" isn't a construction, it's a declaration

#

Make sure you give your variable names
type objName(constructorArgs)

#

What you have is equivalent to
statDist test_1;

tight nacelle
#

Thank you, so it's just me creating the object wrong and nothing wrong with the class constructor?

#

ohhhh

#

I get it

tight nacelle
#

sorry, coming from python so I think I just brain-dead on this part haha

#

Thanks for your help

#

uhh how do I resolve again

#

!solved

static chasmBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

tight nacelle
#

I feel like trying to learn multiple languages is like writing with a different hand...

wise musk
#

I get the comparison, but I feel like it implies an inherit "dominant" hand/language.
I feel like it's more like learning a new language. Your intuitions from your native tongue will get in your way, but with practice, you can become fluent

tight nacelle
#

I appreciate the motivation. Sometimes, I feel like I'm not gaining any progression with C++, constantly having to refer back to old code I wrote to remember how to write something and always second-guessing whether what I'm writing is efficient or not

#

but the process in itself of learning things I never had to worry about before, like stack vs heap allocation, is very fun

wise musk
#

I do that with French and I LIVE in Quebec XD
Just keep at it, and give yourself grace :)