object

Set array of object to null in C++

允我心安 提交于 2020-08-21 17:23:40
问题 Suppose I have an array of objects of type Foo in C++: Foo array[10]; In Java, I can set an object in this array to null simply by: array[0] = null //the first one How can I do this in C++? 回答1: Use pointers instead: Foo *array[10]; // Dynamically allocate the memory for the element in `array[0]` array[0] = new Foo(); array[1] = new Foo(); ... // Make sure you free the memory before setting // the array element to point to null delete array[1]; delete array[0]; // Set the pointer in `array[0]

Why doesn't Any() work on a c# null object

こ雲淡風輕ζ 提交于 2020-08-21 04:57:28
问题 When calling Any() on a null object, it throws an ArgumentNullException in C#. If the object is null, there definitely aren't 'any', and it should probably return false. Why does C# behave this way? 回答1: When dealing with reference types, a null value is semantically different from an "empty" value. A null string is not the same as string.Empty , and a null IEnumerable<T> is not the same as Enumerable.Empty<T> (or any other "empty" enumerable of that type). If Any were not an extension method

Java access object outside thread

别说谁变了你拦得住时间么 提交于 2020-08-20 12:39:22
问题 I want to access the instance created in t1 from outside the thread, is this possible? So I can close the socket after the thread is executed. Network class: public class Network { Socket socket; public void changeConnection(String command) throws Exception { // Whatever exceptions might be thrown if (command.equals("connect")) { socket = new Socket(server, port); } else if (command.equals("disconnect")) { socket.close(); } } } Main class: public class Project1 { public static void main

Java access object outside thread

爱⌒轻易说出口 提交于 2020-08-20 12:39:22
问题 I want to access the instance created in t1 from outside the thread, is this possible? So I can close the socket after the thread is executed. Network class: public class Network { Socket socket; public void changeConnection(String command) throws Exception { // Whatever exceptions might be thrown if (command.equals("connect")) { socket = new Socket(server, port); } else if (command.equals("disconnect")) { socket.close(); } } } Main class: public class Project1 { public static void main

Pasting a String from excel to Word using word-VBA

為{幸葍}努か 提交于 2020-08-12 00:48:05
问题 I have my DB in Excel and want to consult it to create reports in Word. I have searched and tried different options but none seem to work. Any suggestions would be of great help. I essentially want to paste the content of the second Message box into the word document. Dim ctl As Control Dim some As String Dim objExcel As Object Dim objWord As Object On Error Resume Next Set objExcel = GetObject(, "Excel.Application") If objExcel Is Nothing Then Set objExcel = CreateObject("Excel.Application")

How to dynamically attach a function to an object

回眸只為那壹抹淺笑 提交于 2020-08-11 06:08:54
问题 I know there are a few similar questions already on SO (1, 2, 3) but unfortunately my limited knowledge of JS doesn't allow me to extrapolate the scenarios to my personal use case, hence this question. I have the following piece of code which allows me to dynamically attach to and call from an object some functions, which works fine (available on JsFiddle): JavaScript : $.extend(true, window, { "MyPlugin": { "dynamicFunction": dummy_function } }); function dummy_function() { } function real

How to dynamically attach a function to an object

匆匆过客 提交于 2020-08-11 06:08:45
问题 I know there are a few similar questions already on SO (1, 2, 3) but unfortunately my limited knowledge of JS doesn't allow me to extrapolate the scenarios to my personal use case, hence this question. I have the following piece of code which allows me to dynamically attach to and call from an object some functions, which works fine (available on JsFiddle): JavaScript : $.extend(true, window, { "MyPlugin": { "dynamicFunction": dummy_function } }); function dummy_function() { } function real

Accessing an objects property inside a function

梦想与她 提交于 2020-08-10 21:48:06
问题 I'm trying to access objects properties inside an array in my code to render the text values of input boxes restored after a refresh from the local storage but for some reason when I try to run the for loop inside my appStart() function it gives me: "Uncaught TypeError: Cannot read property 'id' of undefined at appStart". Any insiights of why this happens and how to fix it will be greatly appreciated. const currentDayPlaceholder = $("#currentDay"); const timeInTimeBlocks = $(".input-group

Update the value of an attribute in a postgresql jsonb array of objects across muliple records

故事扮演 提交于 2020-08-10 20:32:28
问题 I am trying to update a value tit in three database records that is part of a jsonb array object to change the title of gid 1 to 'newTitle Group 1' from just 'group 1' using postgresql and python. create table groups (name varchar, grp jsonb) insert into groups (name, grp) values ('joe', [{"gid": "1", "ona": "joe", "tit": "group 1 "}, {"gid": "2", "ona": "harry", "tit": "tester1 group 2"}, {"gid": "3", "ona": "moe", "tit": "group 3"}]), ('harry', [{"gid": "1", "ona": "joe", "tit": "group 1 "}

Does a primitive type multi dimensional array gets casted to Object type in Java?

不羁岁月 提交于 2020-08-10 19:29:05
问题 How come int[] arr = new int[5]; Object[] obj = arr; produces a compilation error while int[][] arr = new int[5][5]; Object[] obj = arr; doesn't? 回答1: int[] is an Object , so array of int[] is an array of Object . 来源: https://stackoverflow.com/questions/62435112/does-a-primitive-type-multi-dimensional-array-gets-casted-to-object-type-in-java