assignment

std::map operator[] and automatically created new objects

I'm a little bit scared about something like this: std::map<DWORD, DWORD> tmap; tmap[0]+=1; tmap[0]+=1; tmap[0]+=1; Since DWORD's are not automatically initialized, I'm always afraid of tmap[0] being a random number that is incremented. How does the map know hot to initialize a DWORD if the runtime does not know how to do it? I...

Cart coding help

I've made a simple Javascript code for a shopping basket but now I have realised that I have made a error with making it and don't know how to fix it. What I have is a HTML file with the Javascript, but in the Javascript I have included the images source and fields that would normally only be in the HTML file but What I am trying to do n...

Adding view cart function

Hey guys need some help in adding a view cart button but I'm stuck not sure how to code it. any help? The way I have coded it is that when a user clicks 'add item' they will get a alert box with info about the total price but I want that to appear in the HTML file but only once I have clicked on 'view cart' and I need it to be in a tabl...

Python dictionary to variable assignments based on key value to variable name

Basically, I want to take a Dictionary like { "a":"bar", "b":"blah", "c":"abc", "d":"nada" } and use it to set variables (in an Object) which have the same name as a key in the dictionary. class Foo(Object) { self.a = "" self.b = "" self.c = "" } So in the the end self.a = "bar", self.b = "blah", etc... (and key "d" is ...

Assign method in Scala.

When this code is executed: var a = 24 var b = Array (1, 2, 3) a = 42 b = Array (3, 4, 5) b (1) = 42 I see three (five?) assignments here. What is the name of the method call that is called in such circumstances? Is it operator overloading? Update: Can I create a class and overload assignment? ( x = y not x(1) = y ) ...

please help me Assignment has more non-singleton rhs dimensions than non-singleton

I have the following error in my code Assignment has more non-singleton rhs dimensions than non-singleton This is the code: string =['d:\face\face\ffw' int2str(r) '_' int2str(Sel(nSelRow,t)) '.bmp']; A = imread(string); B = im2double(A); Train_Dat(:,:,s)=B; Update 1: When I updated the code we got new error in the next r...

Who deletes the copied instance in + operator ? (c++)

Hello, I searched how to implement + operator properly all over the internet and all the results i found do the following steps : const MyClass MyClass::operator+(const MyClass &other) const { MyClass result = *this; // Make a copy of myself. Same as MyClass result(*this); result += other; // Use += to add other to t...

C++ assignment - stylish or performance?

Having been writing Java code for many years, I was amazed when I saw this C++ statement: int a,b; int c = (a=1, b=a+2, b*3); My question is: Is this a choice of coding style, or does it have a real benefit? (I am looking for a practicle use case) I think the compiler will see it the same as the following: int a=1, b=a+2; int c = b*...

Problem with casting x<char> to x<t>

Hey guys I cant manage with this code. The idea is to return default English alphabet in case of erroneous create method execution. Thanks. An idea to override explicit operator is good, but i cant imagine an implementation of casting. namespace trie { class AlphabetFactory<T> where T: IConvertible { pub...

Using a class with const data members in a vector

Given a class like this: class Foo { const int a; }; Is it possible to put that class in a vector? When I try, my compiler tells me it can't use the default assignment operator. I try to write my own, but googling around tells me that it's impossible to write an assignment operator for a class with const data members. One post I...

T-SQL Re-Assigning Order Numbering

Say I have a table with a field called "ordernum" that denotes the order of a given set of rows. Now imagine that I delete one of these rows. What type of query would work best for re-assigning the order numbers so that they remain sequential? Here's an example: id group_id name ordernum active ----------------...

Trouble assigning a tr1::shared_ptr

I've got a class that has a tr1::shared_ptr as a member, like so: class Foo { std::tr1::shared_ptr<TCODBsp> bsp; void Bar(); } In member function Bar, I try to assign it like this: bsp = newTCODBsp(x,y,w,h); g++ then gives me this error no match for ‘operator=’ in ‘((yarl::mapGen::MapGenerator*)this)->yarl::mapGen::MapGene...

I want to ask if a pointer is assigned or not in c

How can i write an if statement which tells to the program if the pointer is assigned or not? WRONG example if (*badpdr[0]==0); ?? ...

How can I implicitly convert another struct to my Type ?

Hello, As it is MyClass x = 120;, is it possible to create such a custom class? If so, how can I do that? ...

How to dynamically assign a value to a class property in PHP?

I would like to assign a value in a class property dynamically (that is referring to it using a variable). #Something like: setPropValue($obj, $propName, $value); ...

Problem with assigning elements of a class array to individual variables in MATLAB

This is a bit of a duplicate of this question, this question, and this question, however those solutions don't work, so I'm asking mine. I've got an array of locally defined classes and I'd like to assign it to multiple, individual variables. This pattern doesn't work: %a is 2x1 of MyClass temp = mat2cell(a); [x,y] = temp{:}; %throws:...

Parse text file and assign parts to columns

I receive a tab-delimited text file that must be parsed. Once parsed, the parts must be assigned to specific columns. Here is an example of the code I'm using to do this: string path = "C:\\Users\\Robert\\Desktop\\Test.txt"; FileInfo fileInfo = new FileInfo(path); using (StreamReader streamReader = fileInfo.OpenText()) ...

How can this code be further optimized?

I just got a code handed over to me. The code is written in C# and it inserts realtime data into database every second. The data is accumulated in time which makes the numbers big. The data is updated within the second many times then at the end of the second result is taken and inserted. We used to address the dataset rows directly w...

Variable assignment...

variables a, b, c and d all need to be set to 'foo'. Is there a way to accomplish this in one swooping assignment? Like: a, b, c, d = 'foo' ...

simultaneous variable assignation in pascal

I wish to do simultaneous variable assignment in Pascal. As far as I know, it's not possible. Googling on the issue, I can see that many programming languages implement that, but I can't find how to do it in Pascal. For example, in Python I can do this: (x, y) = (y, x) In Pascal, I need an additional variable to hold the value of x ...