new

What is the difference between the following?

Possible Duplicate: Do the parentheses after the type name make a difference with new? Assuming A is a class properly defined with constructors etc., what is the difference between these? A *ptrA = new A; A *ptrA = new A(); ...

javascript new self invoking function

Hey, I've got a question about self invoking functions in javascript. What I'm doing is something similar to the following myNamespace = {}; //namespace for holding any objects/functions //helpModule as an example myNamespace.HelpModule = new (function(){ this.abc = '123'; //lots of other code in here... })(); now I'm abl...

checking for failed new

why does this ATL/COM code check for successful alloc? I would have expected a custom allocation to be visible through CoGetALloc or some such api. A standards-conforming C++ runtime should be throwing std::bad_alloc, but then again maybe the allocator has indeed been traded out for a non-throwing impl. DDClientData* pNewData = new DDCl...

help with static variables in java

I have a class, class MyClass { private int val; public static final MyClass myObject = new MyClass(1); MyClass(int a){ val = a; } public int getVal(){ return val; } public MyClass func1(){ MyClass temp = myObject; temp.val = 2; return temp; } public static void...

C++: Delete this?

Hi, Is it allowed to delete this; if it the delete-statement the last statement that will be executed in that instance of the class? Or is it maybe allowed to delete that instance in a method called at the last statement in that class? Something like: void doStuff() { //blah blah, stuff, you know... delete changeModule(new Ma...

C++: new, memory understanding question

hi there, why doesn't this work: Snippet 1: int *a = new int[6]; (*a)[0]=1; while this is working Snippet 2: int myint = 0; int *ptr = *ptr=1; I know that if i use a[0]=1 in snippet 1 it will work. But for me that makes no sense, cos for me it looks that a[0]=1 means: put value 1 to adress a[0]. In other words I put the value...

No matching function for call to operator new

I'm trying to wrap a class from a library I'm using in Lua. Specifially, I'm trying to wrap the color class from SFML. The full source for the color class can be seen here and here. This is the function that's that I'm failing in. int SFColor_new(lua_State* L) { // omitting part where I set r, g, b, and a new (lua_newuserdata...

Why should I avoid using malloc in c++?

Possible Duplicates: What is the difference between new/delete and malloc/free? In what cases do I use malloc vs new? Why should I avoid using malloc in c++? ...

How to 301 root site to new folder but allow new website on root

Ok let me see if I can explain this easily I have a forum that was hosted as my home page on www.mysite.com respectively. It's well indexed and I'd hate to lose any ranking. Today I moved the entire root site from the root domain to www.mysite.com/forum to make way for our new CMS system which will now be the home page. (This is to he...

Calling delete on two pointers to the same object.

I'm having a problem with a couple of event handler classes I'm trying to write. Basically, the idea is to have an event handler class for each logical group of objects. In most cases, the events are between objects and their handler, but in some cases events are also sent between handler objects as well. I've written the code such that...

Decimal to Binary, strange output

I wrote program to convert decimal to binary for practice purposes but i get some strange output. When doing modulo with decimal number, i get correct value but what goes in array is forward slash? I am using char array for being able to just use output with cout <<. // web binary converter: http://mistupid.com/computers/binaryconv.htm ...

assign elements in vector declared with new. C++

I am trying to use a large 2D vector which I want to allocate with new (because it is large). if I say: vector< vector<int> > bob; bob = vector< vector<int> >(16, vector<int>(1<<12,0)); bob[5][5] = 777; it works. But if I say: std::vector< std::vector<int> > *mary; mary = new vector< vector<int> >(16, vector<int>(1<<12, 0)); mary[5]...

C++: What does it mean to "new" a collection that will keep growing?

Hi all, I am new to C++. What does it mean exactly to "new" a collection? For example: UnicodeStringList* tmp = new UnicodeStringList; // where UnicodeStringList is typedef to std::list<UnicodeString> When you "new" something you have to know exactly how big you need it to be, right? So when I use the assignment constructor to c...

How do I create an instance of a trait in a generic method in scala?

I'm trying to create an instance of a trait using this method val inst = new Object with MyTrait This works well, but I'd like to move this creation in to a generator function, ie. object Creator { def create[T] : T = new Object with T } I'm obviously going to need the manifest to somehow fix the type erasure problems, but before...

I'm doing funky things with placement new, and things are failing. Workarounds?

I have a very large, spread out class that is essentially a very contrived two dimensional linked list. I want to be able to "compile" it, by which I mean I want to finalize the list, so that only read accesses may be made, and then move all the elements into contiguous memory spaces. My rough solution is this: #include <new> ... MyLis...

[C++] Why doesn't delete destroy anything ?

I'm playing a little with memory dynamic allocation, but I don't get a point. When allocating some memory with the new statement, I'm supposed to be able to destroy the memory the pointer points to using delete. But when I try, this delete command doesn't seem to work since the space the pointer is pointing at doesn't seem to have been ...

c++ constructor with new

I'm making a very dumb mistake just wrapping a pointer to some new'ed memory in a simple class. class Matrix { public: Matrix(int w,int h) : width(w),height(h) { data = new unsigned char[width*height]; } ~Matrix() { delete data; } Matrix& Matrix::operator=(const Matrix&p) { ...

LINQ to SQL Select new as Custom Type not working!

Hi, can anyone tell me why this doesnt work? public class GeocodeCoord { public string Outcode { get; set; } public int X { get; set; } public int Y { get; set; } } List<GeocodeCoord> _geocode; using (MyDataContext db = new MyDataContext()) { _geocode = db.Geocodes.Select(g => new GeocodeCoord { g.postcode, g.x...

add onclick event to newly added element in javascript

Hi I have been trying to add onclick event to new elements I added with javascript. the problem is when I check document.body.innerHTML I can actually see the onclick=alert('blah') is added to the new element. but when I click that element I don't see the alert box is working. in fact anything related to javascript is not working.. here...

Question about the New BSD license

The Zend Framework uses the new BSD license, right? http://framework.zend.com/license I'm developing a CMS that uses ZF. Look at the third condition of the license. Does that mean that I cannot write, in any place of my CMS's website, that it uses ZF? Is it illegal ff I write: "... is a Content Management System based on Zend Framewor...