标签: circular-dependency

ImportError:模型A引用模型B,模型B引用模型A.

我认为这比Django更像是一个蟒蛇问题.

但基本上我在模特A做:

from myproject.modelb.models import ModelB
Run Code Online (Sandbox Code Playgroud)

在模型B:

from myproject.modela.models import ModelA
Run Code Online (Sandbox Code Playgroud)

结果:

无法导入名称ModelA

我做了一些禁止的事吗?谢谢

python django circular-dependency

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

我可以在 Matrix 类的迭代器中避免循环依赖吗?

我们有两个班级:

template<typename T, typename Size, typename Stack, typename Sparse>
class Matrix
Run Code Online (Sandbox Code Playgroud)

template<typename T, typename Size>
class Iterator
Run Code Online (Sandbox Code Playgroud)

Matrix 应该能够返回开始和结束迭代器,并且 Iterator 将保持对 Matrix 的引用以通过其接口访问元素。我们不希望 Iterator 依赖于 Matrix 的内部存储来防止耦合。我们如何解决这个循环依赖问题?

(内部Storage类与Matrix类具有相同的模板参数,与Matrix本身具有相同的访问过程)

c++ templates class circular-dependency

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

boost :: shared_ptr使用weak_ptr循环中断

我目前的情况如下:

struct A {  
  shared_ptr<B> b;  
};  
struct B {  
  shared_ptr<A> a;  
};

//...
shared_ptr<A> a(new A());
shared_ptr<B> b(new B());  
a->b(b);
b->a(a);
Run Code Online (Sandbox Code Playgroud)

我知道这不起作用,因为引用将继续指向彼此.我也被告知weak_ptr解决了这个问题.

但是,weak_ptr没有得到或->超载.我听说过"使用lock()",但任何人都可以提供如何正确执行此操作的代码示例吗?

c++ boost smart-pointers circular-dependency weak

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

c ++如何处理循环依赖?

通常,如果我的#include链变为循环,我通过用前向声明替换#includes中的一个来解决它,然后将依赖于此类型的所有函数实现移动到cpp文件中,其中我改为#include头.

但是 - 在某些情况下,将函数实现放入cpp文件是很糟糕的 - 特别是在处理模板或内联函数时.

因此 - 是否有其他方法来处理循环#include链而不是使用前向声明?

谢谢!

c++ circular-dependency include

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

处理循环对继承的依赖

我将在这个问题上使用C++übernbb,并询问在继承时如何处理循环依赖关系是最好的方法.

设置很简单:Scene类扩展了Actor; 场景有一个指向Actors矢量的指针; Actor有(父)场景的指针.

至于我得到的包含文件:

Scene.h:

#include <string>
#include <vector>
using namespace std;

#ifndef __Scene_h__
#define __Scene_h__

#include "Actor.h"

namespace myns
{
    // class Actor;
    class Scene;
}

namespace myns
{
    class Scene: public myns::Actor
    {
        /* private class attributes... */

        public:
            /* public class attributes... */

            std::vector<myns::Actor*> actors;

            Scene(/* arguments */);

            /* public class methods... */
    };
}

#endif
Run Code Online (Sandbox Code Playgroud)

Actor.h

#include <string>
#include <vector>
using namespace std;

#ifndef __Actor_h__
#define __Actor_h__

#include "Scene.h"

namespace myns
{
    // class Scene; …
Run Code Online (Sandbox Code Playgroud)

c++ architecture class circular-dependency

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

c ++前向声明和不完整类型

你好,我在使用前向声明时遇到了麻烦.我无法访问转发的类函数,但我需要这样做.

这是我的Window.h:

#include "Tab.h"  // Needed because Window will create new Tabs

class Window {
  public:
    ...
    void doSome();

};
Run Code Online (Sandbox Code Playgroud)

这是Tab.h:

class Window;  // forward delcaration

class Tab {

public:
  class Tab(Window *parent);
  void callParentFunction();

private:
  Window *m_parent;
};
Run Code Online (Sandbox Code Playgroud)

最后,Tab.cpp:

#include "Tab.h"

Tab::Tab(Window *parent) {
  m_parent = parent;
}

Tab::callParentFunction() {
  m_parent->doSome();  // Error
}
Run Code Online (Sandbox Code Playgroud)

编译器返回以下错误:无效使用不完整类型'struct Window'

如何知道它已经包含Tab.h来创建标签,我如何访问父节点的功能?如果我不能,你建议我做什么?

c++ circular-dependency forward-declaration incomplete-type

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

在Go中修复导入周期

所以我要解决这个导入周期。我有以下模式:

view/
- view.go
action/
- action.go
- register.go
Run Code Online (Sandbox Code Playgroud)

总体思路是,操作是在视图上执行的,并由视图执行:

// view.go
type View struct {
    Name string
}

// action.go
func ChangeName(v *view.View) {
    v.Name = "new name"
}

// register.go
const Register = map[string]func(v *view.View) {
    "ChangeName": ChangeName,
}
Run Code Online (Sandbox Code Playgroud)

然后在view.go中调用它:

func (v *View) doThings() {
    if action, exists := action.Register["ChangeName"]; exists {
        action(v)
    }
}
Run Code Online (Sandbox Code Playgroud)

但这会导致一个周期,因为View依赖于Action包,反之亦然。我该如何解决这个周期?有其他方法可以解决此问题吗?

dependencies circular-dependency go

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

当条件时 Joi 循环依赖错误

我有 3 个查询参数经度纬度半径

我有 3 个可能的条件:

  • 半径- 空,经度纬度,有一些值
  • 所有 3 个参数都有值
  • 所有 3 个参数为空

在所有其他情况下发送验证错误。

例如

经度=3.12 - 错误

纬度=2.12,半径=3.2 - 误差

经度=12.12,纬度=2.12 - 好的

我的架构看起来像这样:

const schema = Joi.object().keys({
    longitude: Joi.number().optional().error(new Error('LBL_BAD_LONGITUDE'))
      .when('latitude', { is: Joi.exist(), then: Joi.number().required() })
      .when('radius', { is: Joi.exist(), then: Joi.number().required() }),
    latitude: Joi.number().optional().error(new Error('LBL_BAD_LATITUDE'))
      .when('longitude', { is: Joi.exist(), then: Joi.number().required() })
      .when('radius', { is: Joi.exist(), then: …
Run Code Online (Sandbox Code Playgroud)

validation circular-dependency node.js joi

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

半圆中的JavaFX圆形径向渐变辐射

我需要向减法圆添加圆形径向渐变。我一直在尝试,但我无法获得圆形渐变。

圆形径向梯度试验

1:整圆2:整圆径向渐变3:减圆4:减圆中的圆形径向渐变(不是我想要的)5:减圆中的圆形径向渐变。这就是我想要获得的。

一旦我得到减去的圆 (3),我就会应用径向渐变,但我得到的是 (4) 而不是 (5)。

int x = 0.5;
int y = 0.5;

RadialGradient gradientCut = new RadialGradient(0, 0, x, y, 1, true, CycleMethod.NO_CYCLE, new 
Stop[] {
            new Stop(0, Color.ORANGE),
            new Stop(0.2, Color.YELLOW),
            new Stop(0.5, Color.TRANSPARENT)
});

Rectangle rect = new Rectangle(0, 0, 1000, 75);

Shape cutCircleGradient = Shape.intersect(circleGradientCut, rect);
cutCircleGradient.setFill(gradientCut);
Run Code Online (Sandbox Code Playgroud)

我也尝试更改值 x 和 y 但我没有得到我想要的。

gradient javafx circular-dependency shapes intersect

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

导入自身的 Python 程序

我在其中创建了一个以challenge.py以下代码命名的文件:

import challenge

def main():
     print('Circular much...')

challenge.main()
Run Code Online (Sandbox Code Playgroud)

由此,我期望 python 由于导入正在运行的文件的循环导入而引发错误,但我发现在 python 3.7 和 3.8 上,该文件运行并打印了Circular much...两次。我会理解一次,因为这意味着文件的其余部分在导入时没有运行,我会理解递归错误,因为它在堆栈中无限地运行了challenge.main(),但我不明白为什么会这样打印两次然后停止?

python recursion circular-dependency python-3.x

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