未找到标识符convertToHSL
Identifier not found convertToHSL
本文关键字:convertToHSL 标识符 更新时间:2023-10-16
当我在主方法中调用convertToHSL(c1)时,我得到一个未找到的错误标识符。我不明白我的代码的问题是什么。请帮助。我的代码如下:
#include "stdafx.h"
#include "q3.h"
#include <cmath>
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char* argv[])
{
Color c1(1,1,1);
HSL h=convertToHSL(c1);
getchar();
getchar();
return 0;
}
Color::Color(){}
Color::Color(float r,float g,float b){
this->r=r;
this->g=g;
this->b=b;
}
Color::~Color(void){}
Color Color::operator+(Color c) {
return Color(r*c.r,g*c.g,b*c.b);
}
Color Color::operator*(float s) {
return Color(s*r,s*g,s*b);
}
HSL::HSL() {}
HSL::HSL(float h,float s,float l) {
this->h=h;
this->s=s;
this->l=l;
}
HSL::~HSL(void){}
HSL convertToHSL(Color const& c) {
return HSL(0,0,0);
如果没有声明convertToHSL
,则在main()上是未知的:将main()替换为所有其他函数下面的文件末尾
在调用convertToHSL
时(在main
中),编译器根本不知道它的存在,因为它还没有"看到"它(它还没有被声明)。
因此,为了能够从main
调用这个函数,要么将convertHSL
的定义移到main之上,要么至少在main之上预先声明它(不定义它)。或者,如果也要从其他文件中使用它,则将其声明放入头文件中(其定义可能放入单独的源文件中,或者使用inline
说明符直接放入头文件中)。
相关文章:
- 调用具有未标识类型的类的方法
- 函数返回的 rvalue 引用(表达式)是 xvalue - 但没有标识?
- OOP 标识派生对象
- assert() 在发布模式下充当标识函数吗?
- AddressSanitizer 将 std::vector<T>::p ush_back 标识为释放后堆使用错误的原因
- 标识gdb调试器中符号的源文件名
- 如何跳过 CMake 编译器标识?
- 如何创建一个程序来标识最长的子字符串回文,而不考虑字母大小写
- 具有基于标识的相等性的有序关联容器
- 标识线程
- 一种类型特征,标识哪个类提供通过重载解析选择的函数
- C++ - 在运行时从基类指针标识派生类
- 标识使用的设计模式名称
- 使用 lambda 修改由打包参数标识的引用
- 使用 googletest 在类型参数化测试中标识使用的基类
- 如何获取由文件标识的流对象?
- 左值引用在传递标识函数后变得无效
- 共享指针交换方法标识更改
- 如何标识其功能当前正由可执行文件执行的共享库
- 在同一标头中定义但在类外部定义的模板构造函数未标识