程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了没有已知的从 float [4][4][D] 到 float (*)[4][D] C++ 的转换大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决没有已知的从 float [4][4][D] 到 float (*)[4][D] C++ 的转换?

开发过程中遇到没有已知的从 float [4][4][D] 到 float (*)[4][D] C++ 的转换的问题如何解决?下面主要结合日常开发的经验,给出你关于没有已知的从 float [4][4][D] 到 float (*)[4][D] C++ 的转换的解决方法建议,希望对你解决没有已知的从 float [4][4][D] 到 float (*)[4][D] C++ 的转换有所启发或帮助;

我在输入 3D 数组作为 c++ 函数的参数时遇到问题。 我拿出了很多代码,留下了最少的代码来了解正在发生的事情。我得到的错误是:

"no matching function for call to 'spatial_correlation'
                spatial_correlation(Lattice,L,S,D,distances,types,space_corr);
                ^~~~~~~~~~~~~~~~~~~"

"note: candIDate function not viable: no kNown conversion from 'float [4][4][D]' to 'float (*)[4][D]' for 7th argument
voID spatial_correlation(char Lattice[S],const int L,const int S,const int D,vector<float> distances," 
#include <vector>

const int L = 10;
const int S = L*L;

voID spatial_correlation(char Lattice[S],char types[4],float space_corr[4][4][D])
{
     //Finds the spatial correlation. Code not relevant
}

int main()
{
    char types[4] = {'A','B','C','D'};
    vector<float> distances;
    get_distances(Lattice,distances);
    const int D = distances.size();
    float space_corr[4][4][D];

    spatial_correlation(Lattice,space_corr);

    return 0;
}

解决方法

这是一个起点 that builds,使用现代 C++ 习语,您可以在此基础上进行扩展。

#include <vector>
#include <array>
  
void spatial_correlation(
    const std::vector<char>& Lattice,int L,// const no needed,it's a copy here
    const std::vector<float>& distances,const std::array<char,4>& types,const std::array<std::array<std::vector<float>,4>,4>& space_corr
)
{
    auto D = distances.size();
    auto S = L*L;
     //Finds the spatial correlation. Code not relevant
}

int main()
{
    std::array<char,4> types = {'A','B','C','D'};
    std::vector<float> distances;
//    get_distances(Lattice,L,distances);    ? ? ?
    std::vector<char> Lattice;

    std::array<std::array<std::vector<float>,4> space_corr;

    spatial_correlation(Lattice,distances,types,space_corr);
}

大佬总结

以上是大佬教程为你收集整理的没有已知的从 float [4][4][D] 到 float (*)[4][D] C++ 的转换全部内容,希望文章能够帮你解决没有已知的从 float [4][4][D] 到 float (*)[4][D] C++ 的转换所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。