new-operator

C++ array creation problem specific to gcc 4.5

时间秒杀一切 提交于 2019-12-05 21:58:15
The following code works under gcc versions 2.9 through 4.4 but not version 4.5: struct Pass { }; int main(void){ Pass **passes = new ( Pass (*[ 10 ]) ); } The specific error message with gcc 4.5 is: prob.cc: In function ‘int main()’: prob.cc:6:31: warning: lambda expressions only available with -std=c++0x or -std=gnu++0x prob.cc:6:38: error: no matching function for call to ‘Pass::Pass(void (&)())’ prob.cc:2:1: note: candidates are: Pass::Pass() prob.cc:2:1: note: Pass::Pass(const Pass&) Adding the requested flag silences the initial warning but does not fix the issue. Could someone explain

JSLint says new keyword is missing [duplicate]

落花浮王杯 提交于 2019-12-05 17:09:23
This question already has an answer here: How to fix JSLint “missing new” error 2 answers Let's say I have some JavaScript that looks like this: function A() { var MyVar, SomeParameter; // do work MyVar = FunctionB(SomeParameter); } JsLint says I'm Missing 'new'. at the line MyVar = FunctionB(SomeParameter); Why should I rewrite as MyVar = new FunctionB(SomeParameter); Is there going to be any benefit? It is the convention that constructors (eg: Array , Object ) are starting with a capital. JSLint complains, because it thinks that you're trying to use a constructor, without new keyword. To fix

Bad allocation exceptions in C++

安稳与你 提交于 2019-12-05 16:41:43
问题 In a school project of mine I was requested to create a program not using STL. In the program I use alot of Pointer* = new Something; if (Pointer == NULL) throw AllocationError(); My question is about allocation errors: 1. is there an automatic exception thrown by new when allocation fails? 2. if so how can I catch it if I'm not using STL ( #include "exception.h ) 3. is using the NULL testing enugh? thank you. I'm using eclipseCDT(C++) with MinGW on windows 7. 回答1: Yes, the new operator will

React/RCTBridgeDelegate.h' file not found

最后都变了- 提交于 2019-12-05 13:21:38
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/RCTBridgeDelegate.h' file not found. Tried to update the react native version react-native run-ios at terminal in mac I expect the build to be successful and see the ios simulator The actual result which i got is build failed and hence cant see the simulator The issue is related to cocoapods dependency manager . open the terminal and then go to your project ios director, and then type "pod init" (If it doesn't

create new application ruby on rails

╄→尐↘猪︶ㄣ 提交于 2019-12-05 12:15:26
I'm bit confused by "easy" working with ruby on rails, cause I already spend three days by trying create an app. I work on site5 hosting, and try to create new app. step by step: $ rails new app -d mysql $ gem install mysql $ gem install mysql2 and after $ rake db:create it report about error Could not find gem 'mysql2 (~> 0.2.6, runtime)' in any of the gem sources listed in your Gemfile. I google it, but still can't fix problem. Can anybody help? Running rails new app -d mysql will automatically add the required gems to your Gemfile, so you shouldn't need to install them manually with the gem

Is it possible to create a function pointer to the a function's `new` operator/constructor?

允我心安 提交于 2019-12-05 10:55:22
If I were to wanted to parameterize creating an object, I could of course make a function which called new on a particular class and passed out a pointer. I am wondering if it's possible to skip that step and pass a function pointer to the new operator itself. boost::lambda provides function wrappers for new and delete . These can be used to easily convert an new call into a function object. operator new (as well as the other flavours) takes care of allocating memory but does not construct objects. In fact its return type is void* . What constructs an object is a new expression , which is part

Can I really initialize an array with round brackets?

限于喜欢 提交于 2019-12-05 08:17:04
Occasionaly, I've made a typo in one place of code of my program: int a = 10; char* b = new char(a); Error is obvious: I've written () instead of []. The strange thing is... code compiled ok, it ran in debugger ok. But compiled .exe outside of debugger crashed a moment after function with these lines was executed. Is second line of code really legitimate? And if it is, what does it mean to compiler? It's a single char with the numerical value of a , in this case 10 . Pointers don't only point to arrays, y'know. You're allocating a single char and assigning it a value from a . It's not

Overriding operator new/delete in derived class

谁说胖子不能爱 提交于 2019-12-05 08:09:48
I have a stateless, abstract base class from which various concrete classes inherit. Some of these derived classes are stateless as well. Because many of them are created during a run, I'd like to save memory and overhead by having all stateless derived classes emulate a singleton, by overriding operator new()/delete(). A simplified example would look something like this: #include <memory> struct Base { virtual ~Base() {} protected: Base() {} // prevent concrete Base objects }; struct D1 : public Base { // stateful object--default behavior int dummy; }; struct D2 : public Base { // stateless

Reversing CRC32

泪湿孤枕 提交于 2019-12-05 08:00:32
问题 I found a code to reverse CRC32 but I don't know how it works, because im not that good in programming, I just started. I just want to compare 2 files, the old and the new one, then in the new fix the CRC32 adding 4 bytes at the end of the file, so the 2 files will have the same CRC32. Here is the code, is in C#: public class Crc32 { public const uint poly = 0xedb88320; public const uint startxor = 0xffffffff; static uint[] table = null; static uint[] revtable = null; public void FixChecksum

How do I get a new object using Ninject as in this example

百般思念 提交于 2019-12-05 07:32:19
问题 I am in need of adding an item of type IVehicle which is injected at runtime from constructor to a for loop. IVehicle vehicle; for (int i=0;i<=someValue;i++) { list.insert(i,vehicle); //some processing to assign values } now because Ivehicle is already injected by this time, my list has same value despite the value on view different and coming through the controller. How can I new up this object everytime EDIT The best way to new up this object everytime I found was to request new from the