小编sjr*_*son的帖子

在C++ 98模式下在Visual Studio 2015中运行项目

我目前有一个项目,我使用最新的编译器(即默认值)在Visual Studio 2015中编程.不幸的是,我要求我的项目在C++ 98环境中编译和执行 - 有没有办法让我在Visual Studio中通过某种方式更改编译器版本来执行此操作,以便我可以检查我的项目是否仍然有效?

此外,在这个项目中我使用FLTK 1.3.3(一个GUI包) - 如果我确实可以在Visual Studio 2015中执行此操作,我是否需要使用C++ 98模式重建此库?

c++ compatibility fltk c++98 visual-studio-2015

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

更新GeometryModel3D Material的单点颜色而不是整个点系统

我无法理解C#WPF项目的颜色/材质系统,目前我正在更新模型每次更新时整个点系统的颜色,而我只想更新单个颜色点(因为它被添加).

AggregateSystem类

public class AggregateSystem {
    // stack to store each particle in aggregate
    private readonly Stack<AggregateParticle> particle_stack;
    private readonly GeometryModel3D particle_model;
    // positions, indices and texture co-ordinates for particles
    private readonly Point3DCollection particle_positions;
    private readonly Int32Collection triangle_indices;
    private readonly PointCollection text_coords;
    // brush to apply to particle_model.Material
    private RadialGradientBrush rad_brush;
    // ellipse for rendering
    private Ellipse ellipse;
    private RenderTargetBitmap render_bitmap;

    public AggregateSystem() {
        particle_stack = new Stack<AggregateParticle>();
        particle_model = new GeometryModel3D { Geometry = new MeshGeometry3D() };
        ellipse = …
Run Code Online (Sandbox Code Playgroud)

c# wpf colors

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

为什么元素需要不断添加到GeometryModel3D属性集合中,这些属性集合已经过计算才能进行渲染?

下面是一个基于我遇到的WPF模型渲染问题的最小,完整和可验证的例子,这里我们只是在任意2D平面上渲染随机分布的"粒子",其中每个粒子的颜色对应于它的产卵顺序.


MainWindow.cs

public partial class MainWindow : Window {
    // prng for position generation
    private static Random rng = new Random();
    private readonly ComponentManager comp_manager;
    private List<Color> color_list;
    // counter for particle no.
    private int current_particles;

    public MainWindow() {
        InitializeComponent();
        comp_manager = new ComponentManager();
        current_particles = 0;
        color_list = new List<Color>();
    }
    // computes the colours corresponding to each particle in 
    // order based on a rough temperature-gradient
    private void ComputeColorList(int total_particles) {
        for (int i = 0; i < …
Run Code Online (Sandbox Code Playgroud)

c# wpf caching rendering

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

在 Cython 外部定义 _Dcomplex

在我作为开发人员的一个包中,我们广泛使用 Cython 来执行涉及复数的繁重计算。该包需要可从 Unix + Windows 系统构建,因此我们需要一种方法来(重新)定义double complex与两者兼容的类型(假设我们使用 MSVC 在 Windows 上编译 Cython 扩展)。Windows 不支持double complexC99,而是定义了自己的类型_Dcomplex(请参阅https://learn.microsoft.com/en-us/cpp/c-runtime-library/complex-math-support?view=vs-2019)。

由于这种不同的类型,人们不能<complex.h>以这种方式(例如)在.pyx文件中进行外部操作:

cdef extern from "complex.h" nogil:
    double cabs(double complex z)
    double carg(double complex z)
    double complex cexp(double complex z)
    double complex conj(double complex z)
    double cimag(double complex z)
    double creal(double complex z)
    double complex csqrt(double complex z)
Run Code Online (Sandbox Code Playgroud)

当尝试编译.c其中包含的扩展的结果文件(使用 MSVC)时,您会收到如下错误:

error C2061: syntax error: identifier '__pyx_t_double_complex'
Run Code Online (Sandbox Code Playgroud)

它来自.c文件中的这个块:

#if CYTHON_CCOMPLEX …
Run Code Online (Sandbox Code Playgroud)

python windows cython complex-numbers

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

c ++以对数方式增加循环增量

我想循环这样的整数:

1,2,3,4,5,6,7,8,9,10,20,30,40 ......,100,200,......,1000,2000,......

我有代码执行此操作(如下所示)但是它很麻烦,并且通常不编程以处理不同的停止限制:

int MAX = 10000;

for (int i = 1; i <= MAX; i++) {

    cout << i << endl;

    if (i >= 10 && i < 100) {
        i += 9;
    }

    else if (i >= 100 && i < 1000) {
        i+= 99;
    }

    else if (i >= 1000 && i < 10000) {
        i += 999;
    }

}
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,这是前面提到的指定的情况 - 所以我想知道一种以更一般的方式对其进行编码的方法,因为我的要求MAX将是10 ^ 9的数量级所以使用代码像上面这样太不切实际了.

c++ for-loop logarithm

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

使用 std::tuple_element 时无效使用不完整类型的问题

下面的代码为 a 实现了一个散列函数,std::tuple然后在我的代码库的不同段中使用 a std::unordered_mapof std::tuples。

// compute hash function recursively through each std::tuple element
template<class Tuple, std::size_t N>
struct tuple_hash_compute {
    static std::size_t hash_compute(const Tuple& t) {
        using type = typename std::tuple_element<N-1, decltype(t)>::type; // OFFENDING LINE
        return tuple_hash_compute<Tuple, N-1>::hash_compute(t)
            + std::hash<type>()(std::get<N-1>(t));
    }
};
// base helper
template<class Tuple>
struct tuple_hash_compute<Tuple, 1> {
    static std::size_t hash_compute(const Tuple& t) {
        using type = typename std::tuple_element<0, decltype(t)>::type; // OFFENDING LINE
        return 51U + std::hash<type>()(std::get<0>(t))*51U;
    }
};
// tuple_hash …
Run Code Online (Sandbox Code Playgroud)

c++ stdtuple c++14 stdhash

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

根据模板类型在std :: to_string()和.toString()之间切换

我目前正在PriorityQueue用C++ 编写自己的数据结构,我将其制作成模板类typename T.

toString()我的类的成员函数定义为:

/**
 * @brief Gives a std::string representation of this queue structure
 *
 * The priority queue is returned as a string in the following format:
 *
 * \code{.cpp}
 * Data Item        Priority
 * [Item]           [P1]
 * [Item]           [P2]
 * [Item]           [P3]
 * \endcode
 *
 * where P1 < P2 < P3.
 *
 * @return String representation of this priority queue
 */
std::string toString() const {

    std::string tempString = "";

    // initialise …
Run Code Online (Sandbox Code Playgroud)

c++ string templates c++11

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