new-operator

What is parsing in terms that a new programmer would understand? [closed]

怎甘沉沦 提交于 2019-12-02 13:51:52
I am a college student getting my Computer Science degree. A lot of my fellow students really haven't done a lot of programming. They've done their class assignments, but let's be honest here those questions don't really teach you how to program. I have had several other students ask me questions about how to parse things, and I'm never quite sure how to explain it to them. Is it best to start just going line by line looking for substrings, or just give them the more complicated lecture about using proper lexical analysis, etc. to create tokens, use BNF, and all of that other stuff? They never

new Keyword is used for creating object without assigning to an object reference

亡梦爱人 提交于 2019-12-02 13:28:13
Currently i am referring Thread class in java .so i came across a program in which object is created without referring to to the object reference.can anyone explain the concept here is the code // Create a second thread. class NewThread implements Runnable { Thread t; NewThread() { // Create a new, second thread t = new Thread(this, "Demo Thread"); System.out.println("Child thread: " + t); t.start(); // Start the thread } // This is the entry point for the second thread. public void run() { try { for(int i = 5; i > 0; i--) { System.out.println("Child Thread: " + i); Thread.sleep(500); } }

Android ListView, start new activity

安稳与你 提交于 2019-12-02 13:19:43
Hey can someone tell me how I can start an activity by pressing an item in a listview? Here is a hunch I have: EDIT - I have fixed it i think becuse i get no error messages. but when i will start this activity (Videos) the app carshes and wants to force close whats the problem? help pls :D Here is the source code- package com.alpha.liveshit; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class Videos extends ListActivity { String[] elements = {"video",

Is it possible to create an instance of a class on the stack?

时光毁灭记忆、已成空白 提交于 2019-12-02 10:29:52
I know that in C++ you can create an instance of a class on the stack like MyClass mc = MyClass(8.2); or on the heap like MyClass * mc = new MyClass(8.2); Can you do the same thing in C#? The only way I ever create a class in C# is by new ing it. No, it's not possible. All instances of all classes are always allocated on the heap. It is value types, including user defined struct types, that hold values, rather than references to values elsewhere, that can store a value in whatever location that variable happens to store its value in, which may not be the heap. 来源: https://stackoverflow.com

C++ new / new[], how is it allocating memory?

邮差的信 提交于 2019-12-02 08:45:31
I would like to now how those instructions are allocating memory. For example what if I got code: x = new int[5]; y = new int[5]; If those are allocated how it actually looks like in RAM? Is whole block reserved for each of the variables or block(memory page or how-you-call-it - 4KB of size on 32bit) is shared for 2 variables? I couldn't find answer for my question in any manual. Thanks for all replies. I found on wikipedia: Internal fragmentation of pages Rarely do processes require the use of an exact number of pages. As a result, the last page will likely only be partially full, wasting

Operator delete signature unexpected behavior [duplicate]

二次信任 提交于 2019-12-02 07:54:04
问题 This question already has answers here : What are the basic rules and idioms for operator overloading? (7 answers) Closed 5 years ago . In his book C++ Programming Language(4th ed), stroustroup has mentioned that the global operator new & delete can be overloaded by writing global functions with the following signatures: void* operator new(size_t); // use for individual object void* operator new[](size_t); // use for array void operator delete(void*, size_t); // use for individual object void

Array initialization functions

人盡茶涼 提交于 2019-12-02 05:32:39
问题 I was playing around with C++ and I stumbled upon this problem. I'm trying to initialize an array pointer on the heap, and it works inside the initialize() , where it outputs 69 , but in the main() , it crashes with the error EXC_BAD_ACCESS . #include <iostream> void initialize(int* array, int size) { array = new int[size]; // Testing array[2] = 69; std::cout << array[2] << std::endl; // Works fine } int main() { int size = 3; int* array; // Initializing initialize(array, size); // Testing

Operator new and delete overloading scope

橙三吉。 提交于 2019-12-02 03:05:08
问题 I stumbled over some questions about linkage and overloading of operator new and delete. How far does an global overload of operator new/delete take effect Per translation unit Per linked application with at least one object file overloading these operators What about dynamic linkage? Can there be multiple definitions of these operators? If which one is taken. 回答1: The global allocation and deallocation functions are for the whole application, not per translation unit. Since they're global

Size of array (new[])

梦想与她 提交于 2019-12-02 03:03:15
In debug heap I can get size of array, which was created by new[] : int size = *((int *)((char *)ptr - 16)); It is working correctly if the size of the array is less than 28 (but I don't know why? 0_0). Does this trick working in release mode (not using debug heap)? How I can get size of the array (100% working and stable)? You are relying on an implementation detail. That's how your particular implementation stores the size of the memory region where the array is placed. As you already see, the size of the memory region may be bigger than the size of the allocated array. If you need to know

Constructor invocation without parentheses [duplicate]

牧云@^-^@ 提交于 2019-12-01 18:30:30
This question already has an answer here: Can we omit parentheses when creating an object using the “new” operator? 6 answers Is there any difference between var obj1 = new Constructor; and var obj2 = new Constructor(); given that Constructor is a constructor function? According to the MDN docs : [...] "new foo" is equivalent to "new foo()", i.e. if no argument list is specified, "foo" is called without arguments. 来源: https://stackoverflow.com/questions/11347046/constructor-invocation-without-parentheses