Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've got a compiler error but I can't figure out why.

the .hpp:

#ifndef _CGERADE_HPP
#define _CGERADE_HPP
#include "CVektor.hpp"
#include <string>

class CGerade
{

protected:
    CVektor o, rv;

public:

    CGerade(CVektor n_o, CVektor n_rv);

    CVektor getPoint(float t);

    string toString();
};

the .cpp:

#include "CGerade.hpp"

CGerade::CGerade(CVektor n_o, CVektor n_rv)
{
    o = n_o;
    rv = n_rv.getUnitVector();
}

the error message:

CGerade.cpp:10: error: no matching function for call to ‘CVektor::CVektor()’
CVektor.hpp:28: note: candidates are: CVektor::CVektor(float, float, float)
CVektor.hpp:26: note:                 CVektor::CVektor(bool, float, float, float)
CVektor.hpp:16: note:                 CVektor::CVektor(const CVektor&)
CGerade.cpp:10: error: no matching function for call to ‘CVektor::CVektor()’
CVektor.hpp:28: note: candidates are: CVektor::CVektor(float, float, float)
CVektor.hpp:26: note:                 CVektor::CVektor(bool, float, float, float)
CVektor.hpp:16: note:                 CVektor::CVektor(const CVektor&)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
173 views
Welcome To Ask or Share your Answers For Others

1 Answer

From the looks of it, your CVektor class has no default constructor, which CGerade uses in your constructor:

CGerade::CGerade(CVektor n_o, CVektor n_rv)
{ // <-- by here, all members are constructed
    o = n_o;
    rv = n_rv.getUnitVector();
}

You could (and probably should) add one, but better is to use the initialization list to initialize members:

CGerade::CGerade(CVektor n_o, CVektor n_rv) :
o(n_o),
rv(n_rv.getUnitVector())
{}

Which specifies how the members are initialized. (And above, it was defaulting to the non-existent default-constructor.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...