我完全失去了这个。
编译时,我收到此错误:
错误7错误LNK1120:6个未解析的外部
错误4错误LNK2001:未解析的外部符号“public:double __thiscall Cmyk :: getB2(void)”(?getB2 @ Cmyk @@ QAENXZ)
错误5错误LNK2001:未解析的外部符号“public:double __thiscall Cmyk :: getG(void)”(?getG @ Cmyk @@ QAENXZ)
错误6错误LNK2001:未解析的外部符号“public:double __thiscall Cmyk :: getR(void)”(?getR @ Cmyk @@ QAENXZ)
错误1错误LNK2001:未解析的外部符号“public:double __thiscall Hex :: getB2(void)”(?getB2 @ Hex @@ QAENXZ)
错误2错误LNK2001:未解析的外部符号“public:double __thiscall Hex :: getG(void)”(?getG @hex @@ QAENXZ)
错误3错误LNK2001:未解析的外部符号“public:double __thiscall Hex :: getR(void)”(?getR @ Hex @@ QAENXZ)
这是代码
#ifndef header_h_
#define header_h_
class Spalva
{
public:
double r, g, b2, c2;
public:
Spalva(){}
Spalva(double a, double b, double c, double c2)
{
}
};
class Spalva2 :public Spalva {
public:
Spalva2();
Spalva2(int a, int b, int c);
double getR();
double getG();
double getB2();
Spalva2 operator+(Spalva2 a);
void print();
};
class Hex :public Spalva {
public:
Hex();
Hex(int a, int b, int c);
void hex1();
void hex2();
void hex3();
double getR();
double getG();
double getB2();
};
class Cmyk :public Spalva {
public:
Cmyk();
Cmyk(double a, double b, double c, double d);
double getR();
double getG();
double getB2();
void cmyk();
};
#endif // header_h_
和.cpp文件
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#pragma warning(disable : 4996)
#pragma warning(disable : 4244)
#include "header.h"
using namespace std;
Spalva2::Spalva2() {};
Spalva2 :: Spalva2(int a, int b, int c) {
r = a;
g = b;
b2 = c;
}
Spalva2 Spalva2 :: operator+(Spalva2 a) {
Spalva2 rez;
if (r == 255 && g == 255 && b2 == 255 &&
a.getR() == 255 && a.getG() == 255 && a.getB2() == 255)
{
rez.r = 255;
rez.g = 255;
rez.b2 = 255;
cout << "Nauja RGB spalva:" << endl;
return rez;
}
if (r == 1 && g == 1 && b2 == 1 &&
a.getR() == 1 && a.getG() == 1 && a.getB2() == 1)
{
rez.r = 1;
rez.g = 1;
rez.b2 = 1;
cout << "Nauja RGB spalva:" << endl;
return rez;
}
rez.r = this->r / 2 + a.getR() / 2;
rez.g = this->g / 2 + a.getG() / 2;
rez.b2 = this->b2 / 2 + a.getB2() / 2;
cout << "Nauja RGB spalva:" << endl;
return rez;
}
void Spalva2 :: print() {
cout << getR() << " " << getG() << " " << getB2() << endl;
}
Hex :: Hex() {};
Hex :: Hex(int a, int b, int c) {
r = a;
g = b;
b2 = c;
}
void Hex :: hex1()
{
char buffer[33];
cout << "HEX: #" << setw(2) << setfill('0') << itoa(getR(), buffer, 16);
}
void Hex :: hex2()
{
char buffer[33];
cout << setw(2) << setfill('0') << itoa(getG(), buffer, 16);
}
void Hex :: hex3()
{
char buffer[33];
cout << setw(2) << setfill('0') << itoa(getB2(), buffer, 16) << endl;
}
Cmyk::Cmyk() {}
Cmyk::Cmyk(double a, double b, double c, double d) {
r = a;
g = b;
b2 = c;
c2 = d;
}
double Spalva2 :: getR() {
return this->r;
}
double Spalva2 :: getG() {
return this->g;
}
double Spalva2 :: getB2() {
return this->b2;
}
void Cmyk :: cmyk()
{
double max, temp1, temp2, temp3;
Cmyk rez;
temp1 = getR() / 255;
temp2 = getG() / 255;
temp3 = getB2() / 255;
max = temp1;
if (temp2 > max)
max = temp2;
if (temp3 > max)
max = temp3;
rez.c2 = 1 - max;
rez.r = (1 - temp1 - rez.c2) / (1 - rez.c2);
rez.g = (1 - temp2 - rez.c2) / (1 - rez.c2);
rez.b2 = (1 - temp3 - rez.c2) / (1 - rez.c2);
cout << fixed << setprecision(3) << "C: " << rez.r << " M: " << rez.g << " Y: " << rez.b2 << " K: " << rez.c2 << endl;
}
任何帮助表示赞赏:)
答案 0 :(得分:3)
你忘了实施一些方法。例如,你没有方法的实现:double getR();, double getG();, double getB2();在CPP文件中。 Cmyk班也一样。