class

Check if a circle is contained in another circle

有些话、适合烂在心里 提交于 2020-01-01 03:23:10
问题 I'm trying to check if a circle is contained within another circle. I'm not sure if the math behind it is the problem or if its my if statement because I keep getting True for anything I pass. #Get_center returns (x,y) #Get_radius returns radius length def contains(self,circle): distance = round(math.sqrt((circle.get_center()[0]-self.get_center()[0])**2 + (circle.get_center()[1] - self.get_center()[1])**2)) distance_2 = distance + circle.get_radius() if distance_2 > distance: return True

Initializing global variable class

混江龙づ霸主 提交于 2020-01-01 03:21:27
问题 Apologies for such a basic question but I can't figure it out. I know you can initialize a class like this: QFile file("C:\\example"); But how would you initialize it from a global variable? For example: QFile file; //QFile class int main() { file = ?? //need to initialize 'file' with the QFile class } 回答1: 1. Straightforward answer If the class is assignable/copy constructible you can just write QFile file; //QFile class int main() { file = QFile("C:\\example"); } 2. Use indirection If not,

How to use pyreverse on Windows

点点圈 提交于 2020-01-01 03:18:26
问题 I would like to create diagram class using pyreverse. I download it, and when I use this command: pyreverse.bat -c PyreverseCommand -a1 -s1 -f ALL -o png test.py I get an error "The name 'dot' is not recognized....". What is "dot", how can I create diagram class? Thanks for answers. 回答1: dot is part of Graphviz (http://www.graphviz.org/About.php). You need to install Graphviz and then modify your PATH so Windows (what I assume you are using) can find it. "the command pyreverse generates the

Class type Objective C

感情迁移 提交于 2020-01-01 03:02:17
问题 In the NSObject protocol, it defines a method that is similar to this: -(Class) class What type of object is the Class object? Or is it even an object? What can I do with the object? Can I get the base class or adopted protocols? 回答1: Class is itself a class defined by the Objective-C runtime, akin to the Class class in Java. For example, you can use the function class_getClassName() to get the name of a class: NSObject *o = [[[NSObject alloc] init] autorelease]; NSLog(@"%s\n", class

Can virtual functions be inlined [duplicate]

落爺英雄遲暮 提交于 2020-01-01 02:47:14
问题 This question already has answers here : Are inline virtual functions really a non-sense? (12 answers) inline virtual function (3 answers) Closed 6 years ago . If I define a class like this: class A{ public: A(){} virtual ~A(){} virtual void func(){} }; Does it mean that that the virtual destructor and func are inlined 回答1: Whether the compiler chooses to inline a function which is defined inline is entirely up to the compiler. In general, virtual functions can only be inlined when the

Run all functions in class

☆樱花仙子☆ 提交于 2020-01-01 02:39:14
问题 I am trying to run all the functions in my class without typing them out individually. class Foo(object): def __init__(self,a,b): self.a = a self.b=b def bar(self): print self.a def foobar(self): print self.b I want to do this but with a loop, because my actual class has about 8-10 functions. x = Foo('hi','bye') x.bar() x.foobar() 回答1: You can use dir() or __dict__ to go through all of an object's attributes. You can use isinstance() and types.FunctionType to tell which ones are functions.

Why are function template specializations not allowed inside a class?

▼魔方 西西 提交于 2020-01-01 02:19:34
问题 After having found answers to many of my questions on stackoverflow, I have now come up against a question of which I can't find the answer and I hope that someone is willing to help me! My problem is that I want to do an explicit templatization of a function inside a class in C++. My compiler (g++) and a look in the C++ standard (§14.7.3) tells me that this specialization has to be done in the namespace in which the class is declared. I understand that this implies that I cannot put the

proper way of using es6 classes in a nodejs project

怎甘沉沦 提交于 2020-01-01 02:01:11
问题 I'd like to be able to use the cool es6 classes feature of nodejs 4.1.2 I created the following project: a.js: class a { constructor(test) { a.test=test; } } index.js: require('./a.js'); var b = new a(5); as you can see I create a simple class that it's constructor gets a parameter. and in my include i require that class and create a new object based on that class. pretty simple.. but still i'm getting the following error: SyntaxError: Block-scoped declarations (let, const, function, class)

self:: vs className:: inside static className methods in PHP

泄露秘密 提交于 2020-01-01 01:38:09
问题 I guess there may not be any difference but personal preference, but when reading various PHP code I come across both ways to access the methods class. What is the difference: class Myclass { public static $foo; public static function myMethod () { // between: self::$foo; // and MyClass::$foo; } } 回答1: (Note: the initial version said there was no difference. Actually there is) There is indeed a small diference. self:: forwards static calls, while className:: doesn't. This only matters for

Why don't I have to import a class I just made to use it in my main class? (Java)

爷,独闯天下 提交于 2020-01-01 01:12:08
问题 I am currently learning Java using the Deitel's book Java How to Program 8th edition (early objects version). I am on the chapter on creating classes and methods. However, I got really confused by the example provided there because it consists of two separate .java files and when one of them uses a method from the other one, it did not import the class. It just created an object of that class from the other .java file without importing it first. How does that work? Why don't I need to import