【问题标题】:How to called special functions in the cmath library in C++?如何在 C++ 中调用 cmath 库中的特殊函数?
【发布时间】:2020-06-28 16:16:10
【问题描述】:

我正在尝试定义一个函数,该函数需要我使用称为“关联拉盖尔多项式”的东西。它在库下列出here。在 Visual Studio 代码中,intellisense 将“assoc_laguerre()”预测为一个函数,因此它显然存在!

然而,在构建代码时,它会突出显示 assoc_laguerre() 函数并显示消息:“未找到标识符”。

任何帮助将不胜感激! 谢谢!

代码:

#include <iostream>
#include <vector>
#include <string>
#include<vector>
#include<fstream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<time.h>
#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1
#include<math.h>
#include <stdio.h>
#include <cmath>
using namespace std;

//Function Definitons:
double a = 5.29177210903*pow(10,-11);
// Normalised Radial Component:
double Radial(double r,int n,int l,int Z){
    double rho, prefactor,R,L,M;
    rho = 2*r*Z/(n*a);
    R=pow(pow(rho/r,3)*tgamma(n-l)/(2*n*tgamma(n+l+1)),0.5)*exp(-rho/2)*pow(rho,l);
    L=R*assoc_laguerre(n-l-1,2*l+1,rho);

    M=L*R;
    return M;



}
int main()
{
    vector<string> msg {"End Process."};

    for (const string& word : msg)
    {
        cout << word << " ";
    }
  
}

【问题讨论】:

  • assoc_laguerre 是 added in C++17,所以请确保您的目标至少是那个。
  • 嗨普特南,感谢您这么快回复!我对 C++ 编程很陌生,所以我能问一下你所说的目标是什么意思吗?谢谢
  • 您是否阅读了您提供的链接中的注释?您可能需要检查您的编译器是否实现了上述建议,以及是否为它定义了宏。
  • @FelixHunter Putnam 的意思是确保您在编译时启用了对 c++17 的支持。您还需要确保您的编译器足够新以支持 c++17 扩展。你可以找到很多关于 c++17 以及如何编译它的文章。

标签: c++ identifier cmath


【解决方案1】:

您没有在启用语言标准的 C++ 2017 版本的情况下进行编译。启用它,这应该可用。您的代码使用 GCC 10.1 和 -std=c++17 编译;但如果我们改用-std=c++14,则不会。

GodBolt

【讨论】:

    猜你喜欢
    • 2012-06-12
    • 2021-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 2015-03-15
    • 2011-03-17
    • 1970-01-01
    相关资源
    最近更新 更多