class

How to make constructor accept all type of iterators?

好久不见. 提交于 2019-12-31 04:04:29
问题 I am creating a custom Vector/ArrayList class. But i´m having troubles creating the iterative version of the constructor. The following code works, but the problem is when i want to create ArrayList like this: ArrayList arr(1, 5); The compiler doesn't know what version of the function should pick. How can I solve this? The constructors: ArrayList(const size_type elem_amount, value_type elem) : arr_size { elem_amount }, arr_capacity{ elem_amount } { array = std::uninitialized_fill_n(allocator

Java Reflection. Running a external jar and referring to its classes?

久未见 提交于 2019-12-31 03:59:37
问题 This code snippet allows me to run a jar as part of my program: File f = new File("client.jar"); URLClassLoader cl = new URLClassLoader(new URL[]{f.toURI().toURL(), null}); Class<?> clazz = cl.loadClass("epicurus.Client"); Method main = clazz.getMethod("main", String[].class); main.invoke(null, new Object[]{new String[]{}}); Is there anyway that I can refer to that external program's classes? I want to be able to change the title of its JFrame for instance. 回答1: I believe you could. I'd

Python error TypeError: __init__() takes exactly 2 arguments (1 given)

爱⌒轻易说出口 提交于 2019-12-31 03:47:25
问题 WHilst programming in Python i have come across this error about needing 2 arguments and only having one. TypeError: __init__() takes exactly 2 arguments (1 given) I have tried adding extra arguments and other ways but i have not found away to get it working the argument is the class self argument my code is shown below. import sys, pygame pygame.init() size = width, height = 750, 500 backgroundColour = 23, 195, 74 screen = pygame.display.set_mode((size), 0, 32) class NPC(): npcList = [] def

CKEditor classes being stripped

主宰稳场 提交于 2019-12-31 03:43:46
问题 I have a custom plugin that adds a link with a class attached. When I view this using the Source button it shows the class and looks as it should. However, when I go back to WYSYWIG view and then view the source again the class has been stripped out. Any idea how to stop this happening? Thanks in advance for your help. 回答1: Check this blog post. In CKEditor 4.1 RC we've introduced ACF - Advanced Content Filter. You need to integrate your plugin with it, because otherwise special content

Python class methods changing self

[亡魂溺海] 提交于 2019-12-31 03:30:09
问题 This isn't for anything I'm working on yet, it's just some test code as I'm just learning class methods and suck. But say I have the following code class Test(int): def __init__(self,arg): self = arg def thing(self): self += 10 and going, foo=Test(12) sets foo to 12. However I want it, so when I do, foo.thing(), foo increases by 10. So far, going foo.thing() just keeps it at 12. How would I change this code to do that. 回答1: Because int is a immutable, you cannot magically turn it into a

How can an anonymous class have arguments?

时光怂恿深爱的人放手 提交于 2019-12-31 03:17:05
问题 I'm not a java guy but I've inherited some code I need to patch up. I pulled the source into netbeans and I'm getting the error: Anonymous class implements interface; cannot have arguments. Here's the code: Executor background = Executors.newSingleThreadExecutor(); Runnable mylookupThread = new Runnable(FilePath, SearchIndex) { public void run() { MainWindow.this.processFile(this.val$FilePath); Thread t = new Thread(new lookupThread(MainWindow.arrFile, true, false, this.val$SearchIndex)); t

Preventing class instantiation from other classes

谁都会走 提交于 2019-12-31 02:49:35
问题 I'm working with a domain, view and controllers. Each containing their own classes. The domain contains a lot of classes that should not be instantiated in classes outside of the domain. I was under the impression the default access modifier was going to help me. Making my domain classes their constructors package visible. Turns out any class can still use the constructors after importing the right package.class file. How can I prevent this from happening? 回答1: When you say 'Turns out any

jquery show / hide div on click?

孤街浪徒 提交于 2019-12-31 02:44:28
问题 I'm trying to use jquery to show and hide a div onclick, and, although I'm not getting any errors, it's not showing or hiding anything either. **EDIT - UPDATED ** $(document).ready(function() { $("#nav-inner a").click(function() { var type = $(this).attr("class"); $("div.v1 > div").not("." + type).stop().hide().end().filter("." + type).stop().show(); return false; }); }); Here's the jquery: $(document).ready(function() { if($("#nav-inner")) { $("#nav-inner ul li a").click(function(evt) { var

Warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11?

孤街醉人 提交于 2019-12-31 02:43:08
问题 I have this code class Move { public: Move() { name = ""; type_num = 18; power = 0; accuracy = 0; type = "???"; } Move(string a, int b, int c, int d) { name = a; type_num = b; power = c; accuracy = d; /*lines of code to give type a string variable depending on the value of type_num*/ } private: string name, type; int type_num, power, accuracy; }; class Moveset { public: Moveset() { } private: Move slot1{"MOVE 1", rand() % 18, 10*(rand() % 15 + 1), 5 * (rand() % 11 + 10)}; }; And the compiler

Bind a click event to a method inside a class

余生长醉 提交于 2019-12-31 02:35:09
问题 In the constructor of my object, I create some span tag and I need to refers them to a method of the same object. Here is an example of my code: $(document).ready(function(){ var slider = new myObject("name"); }); function myObject(data){ this.name = data; //Add a span tag, and the onclick must refer to the object's method $("body").append("<span>Test</span>"); $("span").click(function(){ myMethod(); //I want to exec the method of the current object }); this.myMethod = myMethod; function