"No matching constructor for initialization of. . ."
"No matching constructor for initialization of. . ."
我知道有人问过这类问题,我看了那些回答,但仍然觉得我遗漏了一些东西。我得到了这个"没有匹配构造函数错误",因为我没有构造函数,但话虽如此,我所看到的关于构造函数的一切都表明,如果你还没有在类中包含变量名,你就需要它们。但我已经这么做了,还需要构造函数吗?如果我做了,它应该是什么样子?我是c++的新手,正在上课,这是一个作业。
下面是我的sensor_node.h文件和类声明:#ifndef SENSORNODE_H
#define SENSORNODE_H
#include <iostream>
class LOCATION {
float lat, longi, height;
public:
LOCATION (float lat, float longi, float height);
void setx(float xx);
void sety(float yy);
void setz(float zz);
void print();
};
class SensorNode {
char* NodeName;
int NodeID;
LOCATION Node1;
float batt;
int func;
public:
SensorNode(char *n, float x, float y, float z, int i, float ah);
void print();
void setOK(int o);
int getOK();
void setLOC(float longi, float lat, float h);
};
#endif /* defined(__Project_3__sensor_node__) */
这里是我的main.cpp错误(在说"LOCATION"的那行):
#include <iostream>
using namespace std;
#include "sensor_node.h"
int main() {
LOCATION a; SensorNode s1("Pulse",15.9,-30.1,0,157,2.0);
int hold;
实际上,您有一个构造函数:LOCATION (float lat, float longi, float height)
。因为它是唯一的,c++尝试应用它。但是,您没有提供任何参数,因此此构造函数不匹配。
你有一个LOCATION
的构造函数(为什么不一致的资本化,顺便说一下?),它需要三个浮点数,但是行LOCATION a
试图调用默认构造函数,你还没有定义。
相关文章:
- Usages of std::move
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 具有变量Number of Arguments的std::函数的矢量
- Capacity of a deque
- C++如何通过"constructor initialization"初始化行变量?
- 为什么"an inherited constructor is not a candidate for initialization from an expression of the same or
- 如何避免"invalid initialization of reference" C++中琐碎函子的错误
- JNI 失败并显示'Error occurred during initialization of VM'
- CUDA : 错误: 创建推力时"transfer of control bypasses initialization of"::d evice_ptr
- 仅当初始化与声明结合使用时"crosses initialization of variable"
- 另一个"invalid initialization of reference of type"错误
- "invalid initialization of non-const reference of type..." 克隆() 函数错误
- C++ "invalid initialization of non-const reference"错误
- C++:"invalid initialization of non-const reference of type ‘List&’ from a temporary of type ‘List*’"
- 位域"In-class initialization"结果为"error: lvalue required as left operand of assignment"
- "No matching constructor for initialization of. . ."
- 使用模板时出现奇怪的"invalid initialization of non-const reference"
- 如何解决棉绒错误"Reference initialization causes loss of const/volatile integrity"
- Initialization of std::initializer_list