【发布时间】:2020-10-06 10:31:05
【问题描述】:
我是编程新手,希望创建一个类或头文件(老实说,我不确定我说的是什么,初学者物理学家,试图利用我的空闲时间,但我认为这是一个头文件看到即将提到的对象的定义将在其中)。 我在创建向量向量时遇到问题。我认为它是这样完成的:
#include <array>
#include <vector>
constexpr int MaxIterations = 101;
constexpr double aprox_PI = 3.141592653589793238463;
using PiArray = std::array<double, MaxIterations>;
using PiMatrix = std::array<PiArray, MaxIterations>;
using PiVector = std::vector<std::vector<double>> ; //here lies the problem, the ones above work fine.
class MonteCarloPiCalculator{
//some stuff goes in here, like function declarations. The definitions are in another file
}
所以vector的大小和内容可以在后面添加,也可以提前定义。这就是我使用的绘图工具的方式。
auto* gr4 = new TGraph(calc.VectPot.data(), calc.relDiff.data());
从 ROOT TGraph 文件中我发现了这个:
TGraph(const TVectorF &vx, const TVectorF &vy);
TGraph(const TVectorD &vx, const TVectorD &vy);
这意味着我可以使用带有浮点和双精度值的向量。 甚至在编译之前,我在 Visual Studio 中就收到了这条消息:
没有构造函数实例与参数列表参数类型匹配 是: (const std::vector
> *, const std::vector > *)
我将如何解决这个问题?我会很感激我能得到的任何帮助。 提前感谢您的宝贵时间。
【问题讨论】:
-
第一条评论:通常在 C++ 中,我们尽可能避免使用原始指针,而支持智能指针:shared_ptr、weak_ptr 和 unique_ptr。
-
另外,为了解决您的问题,最好有stackoverflow.com/help/minimal-reproducible-example
-
错误只是说明您正在尝试使用错误类型的参数构造对象。
标签: c++ class vector root-framework