g++ no matching function call error(g++没有匹配的函数调用错误)
问题描述
我遇到了编译器错误,但我不知道为什么.
I've got a compiler error but I can't figure out why.
.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();
};
.cpp:
#include "CGerade.hpp"
CGerade::CGerade(CVektor n_o, CVektor n_rv)
{
o = n_o;
rv = n_rv.getUnitVector();
}
错误信息:
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&)
推荐答案
从外观上看,你的 CVektor
类没有默认构造函数,CGerade
在你的构造函数:
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.)
这篇关于g++没有匹配的函数调用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:g++没有匹配的函数调用错误


基础教程推荐
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01