new-operator Questions

3

I know there should be a delete operator with which I'm not concerned in somewhere. I just wondering, wow, it worked. Where is the argument "size" coming from? #include<iostream> #include&lt...
Farant asked 24/8, 2011 at 11:7

2

In some use case, you'll need to allocate storage before creating objects inside this storage. Then in order to create these objects, you may need to use placement new: T *pobj = new(pstorage); ye...

19

Solved

Can the new operator throw an exception in real life? And if so, do I have any options for handling such an exception apart from killing my application? Update: Do any real-world, new-heavy applica...
Montcalm asked 23/3, 2010 at 2:21

4

When I am creating a new Flutter project in Android Studio, lib folder is missing. How to fix it? I run Flutter doctor, everything is fine but I am facing this problem.
Metonym asked 13/2, 2022 at 5:34

9

Solved

Is it okay( and legal) to delete a pointer that has been passed as a function argument such as this: #include<iostream> class test_class{ public: test_class():h(9){} int h; ~test_class()...
Vivanvivarium asked 10/12, 2009 at 15:19

6

I know how to dynamically allocate space for an array in C. It can be done as follows: L = (int*)malloc(mid*sizeof(int)); and the memory can be released by: free(L); How do I achieve the equ...
Hudibrastic asked 21/2, 2016 at 4:44

3

I am trying to create a project in google cloud console, but when I go to "New Project" option the following message appears: "You must select a parent organization or folder." If I press "Brows...
Psychopharmacology asked 11/3, 2019 at 17:23

1

Solved

The documentation for the std::allocator<T>::allocate member function says in ([allocator.members]) that: Remarks: The storage for the array is obtained by calling ​::​operator new ([new.del...
Elephant asked 27/2 at 14:29

16

Solved

I have created a new project called auth using react-native init auth at terminal.When i tried to run the project using react-native run-ios. The build failed and gave a error 'React/RCTBridgeDeleg...
Exsanguinate asked 6/7, 2019 at 18:49

20

Solved

I stumbled upon Stack Overflow question Memory leak with std::string when using std::list<std::string>, and one of the comments says this: Stop using new so much. I can't see any reason you ...
Mckenzie asked 28/6, 2011 at 0:8

4

So I was trying to get back the menu settings that dissapear after ubutu made the upgrade to 22.04 version. Honestly I'm new in all this. This is the code that I'm getting: I try: root@blast-...
Sheathing asked 2/1, 2023 at 17:6

5

Solved

I am confused as to why the new operator isn't working as I expected it to. Note: All classes below are defined in the same namespace, and in the same file. This class allows you to prefix any co...
Rousing asked 18/6, 2010 at 12:38

17

Solved

I'm trying to create a new object of type T via its constructor when adding to the list. I'm getting a compile error: The error message is: 'T': cannot provide arguments when creating an instan...
Intertwine asked 8/5, 2009 at 15:4

12

Solved

I have following code : System.out.println(" | 1 2 3 4 5 6 7 8 9"); System.out.println("----------------------------"); System.out.println(""); I use println to create a new line. Is it possi...
Dhar asked 24/10, 2010 at 12:38

3

Solved

What I am making is a weather forecast website, and what I need is the days of the week (ie. "Sunday", "Monday", etc.). To get tomorrow's date I am just putting "+ 1" like someone suggested in anot...
Fosterfosterage asked 14/2, 2012 at 4:22

6

How do i declare a 2d array using the 'new' operator? My book says this: int (*p)[4]; p=new[3][4]; but it doesn't make sense to me. p is a pointer to an array of 4 ints, so how can it be made to...
Wed asked 8/4, 2012 at 12:5

6

Solved

I want this to tell me the Name of both ItemA and ItemB. It should tell me "Subitem\nSubitem", but instead it tells me "Item\nSubitem". This is because the "Name" variable defined in the Subitem cl...
Thirtieth asked 13/1, 2012 at 1:8

8

Solved

class Foo attr_accessor :name, :age, :email, :gender, :height def initalize params @name = params[:name] @age = params[:age] @email = params[:email] . . . end This seems like a silly wa...
Ferree asked 6/10, 2012 at 19:17

2

Solved

I have a C++ concept for checking that an array of objects can be dynamically allocated: template< class T, int N > concept heap_constructible = requires() { delete[] new T[N]; }; And I fou...
Unconformity asked 22/5, 2023 at 15:48

1

Recently, I was made aware of the potential issues of memory alignment for Fixed-size vectorizable Eigen objects. The correct code as stated in the doc: class Foo { ... Eigen::Vector2d v; ... pu...
Hyatt asked 2/8, 2020 at 12:48

1

Solved

Many answers on this site mentions that delete() calls destructor. But the sample code below seems to call delete() inside the destructor. What is the correct usage of delete() when object is initi...

8

Solved

If 'Test' is an ordinary class, is there any difference between: Test* test = new Test; and Test* test = new Test();
Heliochrome asked 6/3, 2009 at 19:39

3

Here I have defined immutable class str. In __new__ method I am changing the values of instances such as "hello" to uppercase. Why should we do it using __new__ when we can define u...
Implausible asked 9/12, 2021 at 9:1

5

Solved

Recently I thought of converting a side project of mine into Typescript. But I have trouble with calling functions using new. I am trying to call a function imported from another file like this: //...
Pantograph asked 7/3, 2021 at 17:21

5

I need to write a strings into a text file from C#, each string on a new line...How can I do this?
Assemblage asked 17/12, 2009 at 4:57

© 2022 - 2024 — McMap. All rights reserved.