"numrt":尽管定义了该函数,但未找到标识器
"numrt": identifyer not found despite of defining that function
我正在用C++编写一个数学函数库。我做了sqrt函数,它运行得很好。我还试图制作一个根函数,计算一个数字的第n个根。我有三个文件-emath.cpp,emath.hpp,main.cpp(emath是我的库的名称)。
emath.cpp:
namespace emath
{
class emath
{
public:
/* ... */
//Returns value of square root of a number.
static double sqrt(double tur);
//Rerurns value of a root of a number.
static double numrt(int stopien, double tur);
};
}
emath.hpp:
#ifndef EMATH_HPP
#define EMATH_HPP
using namespace std;
namespace emath
{
class emath
{
public:
/* ... */
int emath::derivative(double x)
{
return 0;
}
//****************************************************************
double emath::derivative(double number, int pow)
{
double result = 1;
for (int i = 1; i < pow; i++)
{
result *= number;
}
result *= pow;
return result;
}
//************************************************************************
double emath::derivative(double number, int pow, double numbey)
{
return ((derivative(number, pow) + derivative(numbey)));
}
//************************************************************************
double emath::sqrt(double tur) //This function
{
int a;
static int i = 0;
for (; i * i <= tur; i++)
{
}
if (i * i == tur)
{
return i;
}
a = i;
return sqrtl(a);
}
//************************************************************************
double emath::numrt(int stopien, double tur) //This function
{
int a;
static int i = 0;
for (; i * i <= tur; i++)
{
}
if (i * i == tur)
{
return i;
}
a = i;
static int mul = 1;
for (int p = 0; p < stopien; p++)
{
mul *= i;
}
return numrtel(mul, i, a);
}
private:
//****************************************************************
double emath::sqrtel(double tur, static int k = 0) //Implementation of Newton's Method
{
double a; //Creates a - our xn.
if (k == 1000000)
{
return a;
}
a = a - ((a * a - tur) / derivative(a, 2, - tur)); //Proper implementation os Newton's Method
++k; //k is counter
return sqrtel(a);
}
//***************************************************************
double emath::numrtel(int mul, int i, double tur, static int k = 0)
{
double a; //Creates a - our xn.
if (k == 1000000)
{
return a;
}
a = a - ((mul - tur) / derivative(a, i, - tur)); //Proper implementation os Newton's Method
++k; //k is counter
return numrtel(mul, i, a);
}
}; //end of class
} //end of namespace
#endif // EMATH_HPP
如果我的main.cpp是
#include <iostream>
#include "emath.hpp"
using namespace std;
using namespace emath;
int main()
{
double number;
cin >> number;
cout << sqrt(number);
}
它运行得很好,但如果main.cpp是
#include <iostream>
#include "emath.hpp"
using namespace std;
using namespace emath;
int main()
{
double number;
cin >> number;
cout << numrt(3, number);
}
我得到一个编译器错误:"numrt":找不到标识符。我使用的是带有Qt Creator的MS VS Studio 2012编译器。为什么?
由于在类emath
中声明了numrt()
,因此必须在函数调用中声明该类名:
emath::numrt()
(完整调用,包括名称空间名称为emath::emath::numrt()
。)
我想知道为什么对sqrt()
的调用有效,因为要执行代码,还必须使用emath::sqrt()
来调用它。您确定您的代码是执行的,而不是标准库中的某些代码吗?
相关文章:
- 如何创建迭代器函数
- 使用迭代器的自定义比较器函数
- 为什么我的突变器函数没有设置任何内容?还是我的构造函数?
- 将此私有删除器函数包装在结构中的目的是什么?
- 为什么在类或结构中传递自定义比较器函数?
- 为什么当我们使用等于'='符号比较器函数时,c ++的内置排序函数不起作用?
- 为模板类中的特定类型编写比较器函数
- 包装器函数可以重构吗?
- C++设置器函数崩溃
- 下面的比较器函数在 c++ 中如何工作?
- 在存储库中,筛选器函数返回动态向量或其他存储库
- 如何在类中从排序调用比较器函数C++
- 为什么访问器函数必须是常量?漏洞在哪里?
- 我的基于可变模板的包装器函数有什么问题?
- 如何编码为像 STL IO 操纵器函数这样的样式?
- 创建一个允许轻松创建虚拟函数包装器函数的C++宏
- sort() 方法 c++ 中的比较器函数.为大量数字获得不同的解决方案
- 如何在不使用虚拟的情况下创建装饰器函数
- C++:输入验证器函数
- "numrt":尽管定义了该函数,但未找到标识器