小编Cás*_*nan的帖子

如何最好地在sqlite数据库中存储hashmap

我有一个哈希图定义如下:

  • 键=一年中的月份;
  • 值 = 另一个哈希图,其中:
    • 键 = 月份中的哪一天;
    • 值 = 降雨量。

在数据库中存储此类哈希图的最佳方法是什么?

另请注意,我将存储许多这样的哈希图(代表多个实验运行)。

c++ sqlite hashmap

1
推荐指数
1
解决办法
393
查看次数

将 cmath 包含在 math.h 上会导致错误的结果

编辑测试用例和编译器不一致。最近我做了一个更改,使用更现代的 < cmath > 而不是 < math.h >。虽然编译得很好,没有任何警告,但对一个文件的这一行更改导致我的测试用例失败。根据我的理解,cmath 只是将大部分函数/变量放在 std 命名空间中,并且我没有对该命名空间进行任何更改。

我会注意到我正在使用

  • 开方

  • abs (因为我在这里使用双精度,所以我假设编译器会自动使用 cmath/math.h 形式,而不是 stdlib)

  • 晒黑

排除可能受此单行更改影响的任何文件。我确实有一个已经使用 cmath 的不同文件,但不影响测试。

一个测试用例

#include <iostream>
#include <cmath>
int main() {

    double x = -0.546;
    double y = abs( x / sqrt(x*x + 1.0));
    double z = std::abs( x / sqrt(x*x + 1.0));

    std::cout << "Variable value is " << x << std::endl;
    std::cout << "Value of function using cmath " << z << std::endl;
    std::cout << "Value of function using …
Run Code Online (Sandbox Code Playgroud)

c++ std math.h cmath

1
推荐指数
1
解决办法
295
查看次数

具有头文件头文件的缺点是什么?

我进入了一个项目,该项目采用了一个头文件的方法,MyProject.h该文件包含每个.c文件的所有头文件.每个.c文件都有自己的头文件#include "MyProject.h",无论需要什么库,还有文件所需的任何其他声明.

对我来说,这似乎是多余的,有点不自然,但它编译并随后按预期运行.我的想法是编译器会做更多的工作而不是必要的,并且可能会使.exe过度膨胀.这样做的缺点是什么?

我接下来的一个问题就是说,我使用上面的例子在一个文件中包含了一个像Time.h这样的库.由于MyProject.h,编译器是否只将Time.h构建到二进制文件或现在的每个文件中?结构,枚举等怎么样?

c

0
推荐指数
1
解决办法
277
查看次数

如何使用继承的operator []来防止赋值?

我有一个自定义结构SortedArrayList<T>,根据比较器对其元素进行排序,我想阻止使用operator[].

例:

ArrayList.h

template <typename T> class ArrayList : public List<T> {
    virtual T& operator[](const int& index) override; //override List<T>
    virtual const T operator[](const int& index) const override; //override List<T>
}
Run Code Online (Sandbox Code Playgroud)

SortedLinkedList.h包含以下运算符

template <typename T> class SortedArrayList : public ArrayList<T> {
   public:

   SortedArrayList<T>(const std::function<bool(const T&, const T&)>& comparator);

   T& operator[](const int& index) override; //get reference (LHS)
   const T operator[](const int& index) const override; //get copy (RHS)
}
Run Code Online (Sandbox Code Playgroud)

Test.h

ArrayList<int>* regular = new ArrayList<int>();
ArrayList<int>* sorted = …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance containers list

0
推荐指数
1
解决办法
99
查看次数

标签 统计

c++ ×3

c ×1

cmath ×1

containers ×1

hashmap ×1

inheritance ×1

list ×1

math.h ×1

sqlite ×1

std ×1