cyclic-reference

Cycle in the struct layout that doesn't exist

五迷三道 提交于 2019-11-26 16:50:54
问题 This is a simplified version of some of my code: public struct info { public float a, b; public info? c; public info(float a, float b, info? c = null) { this.a = a; this.b = b; this.c = c; } } The problem is the error Struct member 'info' causes a cycle in the struct layout. I'm after struct like value type behaviour. I could simulate this using a class and a clone member function, but I don't see why I should need to. How is this error true? Recursion could perhaps cause construction forever

shared_ptr and weak_ptr differences

风格不统一 提交于 2019-11-26 15:05:46
问题 I am reading Scott Meyers "Effective C++" book. It was mentioned that there are tr1::shared_ptr and tr1::weak_ptr act like built-in pointers, but they keep track of how many tr1::shared_ptrs point to an object. This is known as reference counting. This works well in preventing resource leaks in acyclic data structures, but if two or more objects contain tr1::shared_ptrs such that a cycle is formed, the cycle may keep each other's reference count above zero, even when all external pointers to

Java Enums: Two enum types, each containing references to each other?

狂风中的少年 提交于 2019-11-26 09:41:14
问题 Is there a way to get around the class-loading issues caused by having two enums that reference each other? I have two sets of enumerations, Foo and Bar, defined like so: public class EnumTest { public enum Foo { A(Bar.Alpha), B(Bar.Delta), C(Bar.Alpha); private Foo(Bar b) { this.b = b; } public final Bar b; } public enum Bar { Alpha(Foo.A), Beta(Foo.C), Delta(Foo.C); private Bar(Foo f) { this.f = f; } public final Foo f; } public static void main (String[] args) { for (Foo f: Foo.values()) {

How to deal with cyclic dependencies in Node.js

安稳与你 提交于 2019-11-26 05:40:43
问题 I\'ve been working with nodejs lately and still getting to grips with the module system so apologies if this is an obvious question. I want code roughly like the following below: a.js (the main file run with node) var ClassB = require(\"./b\"); var ClassA = function() { this.thing = new ClassB(); this.property = 5; } var a = new ClassA(); module.exports = a; b.js var a = require(\"./a\"); var ClassB = function() { } ClassB.prototype.doSomethingLater() { util.log(a.property); } module.exports

Circular (or cyclic) imports in Python

大城市里の小女人 提交于 2019-11-25 23:56:40
问题 What will happen if two modules import each other? To generalize the problem, what about the cyclic imports in Python? 回答1: There was a really good discussion on this over at comp.lang.python last year. It answers your question pretty thoroughly. Imports are pretty straightforward really. Just remember the following: 'import' and 'from xxx import yyy' are executable statements. They execute when the running program reaches that line. If a module is not in sys.modules, then an import creates