我有一个班级计算器。
Calculator.h:
#ifndef TASK2_CALCULATOR_H
#define TASK2_CALCULATOR_H
class Calculator{
public:
int add(int a, int b);
int subtract(int a, int b);
int multiply(int a, int b);
int divide(int a, int b);
int square(int a);
double add(double a, double b);
double subtract(double a, double b);
double multiply(double a, double b);
double divide(double a, double b);
double square(double a);
};
#endif //TASK2_CALCULATOR_H
Calculator.cpp:
//
// Created by Gebruiker on 13-12-2018.
//
#include <stdexcept>
#include "Calculator.h"
int Calculator::add(int a, int b) {
return a+b;
}
double Calculator::add(double a, double b) {
return a+b;
}
int Calculator::divide(int a, int b) {
if (b==0){
throw std::logic_error("Can't divide by 0");
}
else{
return a/b;
}
}
double Calculator::divide(double a, double b) {
if (b==0){
throw std::logic_error("Can't divide by 0");
}
else{
return a/b;
}
}
int Calculator::multiply(int a, int b) {
return a*b;
}
double Calculator::multiply(double a, double b) {
return a*b;
}
int Calculator::subtract(int a, int b) {
return a-b;
}
double Calculator::subtract(double a, double b) {
return a-b;
}
int Calculator::square(int a) {
return a*a;
}
double Calculator::square(double a) {
return a*a;
}
我正在尝试运行一些Google测试。当我尝试运行此测试时,出现错误:
/Task2/tests/calc_tests.cpp:11: undefined reference to `calc()'
我的测试台看起来像这样:
#include <gtest/gtest.h>
#include "../Calculator.h"
TEST(calcu, iadd){
Calculator calc;
ASSERT_EQ(calc.add(1, 5), 6);
}
很长一段时间以来,我一直在尝试解决此错误,但我无法使其正常工作。希望您会看到这里发生的事情。
谢谢!