Search Results

Search found 12457 results on 499 pages for 'variable assignment'.

Page 17/499 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • Objective-C member variable assignment?

    - by Alex
    I have an objective-c class with member variables. I am creating getters and setters for each one. Mostly for learning purposes. My setter looks like the following: - (void) setSomething:(NSString *)input { something = input; } However, in C++ and other languages I have worked with in the past, you can reference the member variable by using the this pointer like this->something = input. In objective-c this is known as self. So I was wondering if something like that is possible in objective-c? Something like this: - (void) setSomething:(NSString *)input { [self something] = input; } But that would call the getter for something. So I'm not sure. So my question is: Is there a way I can do assignment utilizing the self pointer? If so, how? Is this good practice or is it evil? Thanks!

    Read the article

  • Formatting a barcode with hyphens in between - Assignment question

    - by capex
    Hi, The assignment at my first year uni computing course says my program should read a barcode number, and then display the same 13 digit barcode number separated by hyphens. For example, 9300675016902 should look like 930-067501-690-1. The restrictions say I can't use the following: No arrays No strings No functions. Any directions on this? (So far I have done this: part1 = barcode/10000000000; which gives me the first three digits, and this: part4 = barcode%10; which gives me the last digit. Thanks in advance!

    Read the article

  • TypeError: 'NoneType' object does not support item assignment

    - by R S John
    I am trying to do some mathematical calculation according to the values at particular index of a NumPy array with the following code X = np.arange(9).reshape(3,3) temp = X.copy().fill(5.446361E-01) ind = np.where(X < 4.0) temp[ind] = 0.5*X[ind]**2 - 1.0 ind = np.where(X >= 4.0 and X < 9.0) temp[ind] = (5.699327E-1*(X[ind]-1)**4)/(X[ind]**4) print temp But I am getting the following error Traceback (most recent call last): File "test.py", line 7, in <module> temp[ind] = 0.5*X[ind]**2 - 1.0 TypeError: 'NoneType' object does not support item assignment Would you please help me in solving this? Thanks

    Read the article

  • error: incompatible types in assignment

    - by ambika
    My C code #include <stdio.h> #include <stdlib.h> #include "help.h" int test(int x, P *ut) { int point = 10; ut->dt[10].max_x = NULL; } int main(int argc, char** argv) { return (EXIT_SUCCESS); } my help.h file code typedef struct{ double max_x; double max_y; }X; typedef struct{ X dt[10]; }P; I got an error i.e error: incompatible types in assignment error comes in here ut->dt[10].max_x = NULL; can anybody help me. thanks in advance.

    Read the article

  • help in security assignment

    - by scatman
    i have to write a program that sniffs network packets (part1-the simple part). and i have to update the program (part2) so that it will be able to terminate connections. the specific requirements are: construct raw packets by specifying data link layer and network layer information including appropriate source and destination MAC and IP addresses. These packets are intended to terminate the connection. To do so, you should used SOCK_RAW as the socket type to be able to set the header information by yourself. can anybody give me some ideas on the second part? should i hijack the session,apply a dos attack on one of the users?? all i need is some tips of how to terminate the connection. i am using c programming language. and this is a course assignment for the security course.

    Read the article

  • Flash AS3: automate property assignment to new instance from arguments in constructor

    - by matt lohkamp
    I like finding out about tricky new ways to do things. Let's say you've got a class with a property that gets set to the value of an argument in the constructor, like so: package{ public class SomeClass{ private var someProperty:*; public function SomeClass(_someProperty:*):void{ someProperty = _someProperty; } } } That's not exactly a hassle. But imagine you've got... I don't know, five properties. Ten properties, maybe. Rather then writing out each individual assignment, line by line, isn't there a way to loop through the constructor's arguments and set the value of each corresponding property on the new instance accordingly? I don't think that the ...rest or arguments objects will work, since they only keep an enumerated list of the arguments, not the argument names - I'm thinking something like this would be better: for(var propertyName:String in argsAsAssocArray){this[propertyName] = argsAsAssocArray[propertyName];} ... does something like this exist?

    Read the article

  • assignment vs std::swap and merging and keeping duplicates in seperate object

    - by rubenvb
    Say I have two std::set<std::string>s. The first one, old_options, needs to be merged with additional options, contained in new_options. I can't just use std::merge (well, I do, but not only that) because I also check for doubles and warn the user about this accordingly. To this effect, I have void merge_options( set<string> &old_options, const set<string> &new_options ) { // find duplicates and create merged_options, a stringset containing the merged options // handle duplicated the way I want to // ... old_options = merged_options; } Is it better to use std::swap( merged_options, old_options ); or the assignment I have? Is there a better way to filter duplicates and return the merged set than consecutive calls to std::set_intersection and std::set_union to detect dupes and merge the sets? I know it's slower than one traversal and doing both at once, but these sets are small (performance is not critical) and I trust the Standard more than I trust myself.

    Read the article

  • simple assignment not working for me: iphone sdk

    - by tak
    Hi all. Can someone please explain to me why this simple assignment doesn't work. Here is the code loanDetails.currency = myCurrency; NSLog(@" Value %@",myCurrency); NSLog(@" Value %@",loanDetails.currency); NSLog(@" Value %@",myCurrency); the output is:- 2010-05-05 23:00:44.394 ExpenseTracker[3576:207] Value AFA 2010-05-05 23:00:44.750 ExpenseTracker[3576:207] Value (null) 2010-05-05 23:00:45.095 ExpenseTracker[3576:207] Value AFA And the definition is as: @property (nonatomic,retain) NSString *currency;

    Read the article

  • assignment makes pointer from integer without a cast

    - by mrblippy
    hi, i am trying to make a linked list and create some methods. but i am getting the error assignment makes pointer from integer without a cast. #include <stdio.h> #include <stdlib.h> #include "students.h" node_ptr create(void) { node_ptr students = (node_ptr) malloc(sizeof(struct node)); students->ID = 0; students->name = NULL; students->next = NULL; return students; } void insert_in_order(int n, node_ptr list) { node_ptr before = list; node_ptr new_node = (node_ptr) malloc(sizeof(struct node)); new_node->ID = n;//error is here i think while(before->next && (before->next->ID < n)) { before = before->next; } new_node->next = before->next; before->next = new_node; }

    Read the article

  • cannot convert ‘mcontext_t*’ to ‘sigcontext*’ in assignment

    - by user353573
    i have checked asm/ucontext.h it should be sigcontext, but why pop up the error message cannot convert ‘mcontext_t*’ to ‘sigcontext*’ in assignment #include <stdio.h> #include <signal.h> #include <asm/ucontext.h> static unsigned long target; void handler(int signum, siginfo_t *siginfo, void *uc0){ struct ucontext *uc; struct sigcontext *sc; uc = (struct ucontext *)uc0; sc = &uc->uc_mcontext; sc->eip = target; } struct ucontext { unsigned long uc_flags; struct ucontext *uc_link; stack_t uc_stack; struct sigcontext uc_mcontext; sigset_t uc_sigmask; /* mask last for extensibility */ };

    Read the article

  • rspec mocking object property assignment

    - by charlielee
    I have a rspec mocked object, a value is assign to is property. I am struggleing to have that expectation met in my rspec test. Just wondering what the sytax is? The code: def create @new_campaign = AdCampaign.new(params[:new_campaign]) @new_campaign.creationDate = "#{Time.now.year}/#{Time.now.mon}/#{Time.now.day}" if @new_campaign.save flash[:status] = "Success" else flash[:status] = "Failed" end end The test it "should able to create new campaign when form is submitted" do campaign_model = mock_model(AdCampaign) AdCampaign.should_receive(:new).with(params[:new_campaign]).and_return(campaign_model) campaign_model.should_receive(:creationDate).with("#{Time.now.year}/#{Time.now.mon}/#{Time.now.day}")campaign_model.should_receive(:save).and_return(true) post :create flash[:status].should == 'Success' response.should render_template('create') end The problem is I am getting this error: Spec::Mocks::MockExpectationError in 'CampaignController new campaigns should able to create new campaign when form is submitted' Mock "AdCampaign_1002" received unexpected message :creationDate= with ("2010/5/7") So how do i set a expectation for object property assignment? Thanks

    Read the article

  • JS assignment order of properties in objects

    - by devdev
    Just had a quick question about why a certain order of assignment works and another doesn't. I wanted to create a simple "inherit" / "copy" function (just for testing it) that copies properties from one object to another: var cat = { tail:"yes", hairy:"yes, hairy" }; var dog = { sick:"extremely ill"}; function inherit(obj1, obj2) { for (var p in obj1) { obj2[p] = obj1[p]; // this works, but "obj1[p] = obj2[p];" doesn't. Why?? } } inherit(cat, dog); console.log(dog.tail);

    Read the article

  • Excel Worksheet assignment in VB.Net doesn't compile

    - by Brian Hooper
    I'm converting a VB6 application into VB.Net and having trouble with the basics. I start off with:- Dim xl As Excel.Application Dim xlsheet As Excel.Worksheet Dim xlwbook As Excel.Workbook xl = New Excel.Application xlwbook = xl.Workbooks.Open(my_data.file_name) xlsheet = xlwbook.Sheets(1) but the last line doesn't compile; it reports Option Strict On disallows implicit conversion from 'Object' to 'Microsoft.Office.Interop.Excel.Worksheet' I can make this go away by replacing the line with xlsheet = CType(xlwbook.Sheets(1), Excel.Worksheet) but that does't look like the right thing to do to me. If the assignment is correct, I would have thought the object should naturally have the correct type. So: does anyone know what the correct thing I should be doing here?

    Read the article

  • c++: truth assignment warning with arguments?

    - by John
    I use the following to work with arguments in my programs, but it seems to just hand me a warning (just a warning): "warning: suggest parentheses around assignment used as truth value" The beginning of the code is as follows: enum{OPT_DISP_H = 0x2, OPT_DISP_W = 0x1}; int main(int argc, char *argv[]) { int opt = 0x00; char c; while((++argv)[0] && argv[0][0]=='-'){ while(c =* ++argv[0]) switch(c){ case 'h': opt |= OPT_DISP_H; break; //etc.. The while(c =* ++argv[0]) part being where the warning persists. The code works fine, but what does this warning mean opposed to what is used? I think the code is c = *++argv[0], using the pointer. So why does the single = work and what is really recommended to be used?

    Read the article

  • C++ Generic List Assignment

    - by S73417H
    I've clearly been stuck in Java land for too long... Is it possible to do the C++ equivalent of the following Java code: // Method List<Bar> getBars() { return new LinkedList<Bar>(); } // Assignment statement. List<Foo> stuff = getBars(); Where Foo is a sub-class of Bar. So in C++.... std::list<Bar> & getBars() { std::list<Bar> bars; return bars; } std::list<Foo> stuff = getBars(); Hope that makes sense....

    Read the article

  • Incompatible type in assignment

    - by coure06
    Getting error: Incompatible type in assignment at fValue = ..., see the code static float t = 0; float d = .5; static float fValue = 0; fValue = [self easeOutBounce:t andB:0 andC:30 andD:d]; here is the method -(float) easeOutBounce:(float)t andB:(float)b andC:(float)c andD:(float)d { if ((t/=d) < (1/2.75)) { return c*(7.5625*t*t) + b; } else if (t < (2/2.75)) { return c*(7.5625*(t-=(1.5/2.75))t + .75) + b; } else if (t < (2.5/2.75)) { return c(7.5625*(t-=(2.25/2.75))t + .9375) + b; } else { return c(7.5625*(t-=(2.625/2.75))*t + .984375) + b; } }

    Read the article

  • Solving C++ 'target of assignment not really an lvalue' errors

    - by Jason
    Given this code: void FrMemCopy(void *to, const void *from, size_t sz) { size_t sz8 = sz >> 3; size_t sz1 = sz - (sz8 << 3); while (sz8-- != 0) { *((double *)to)++ = *((double *)from)++; } while (sz1-- != 0) { *((char *)to)++ = *((char *)from)++; } } I am receiving target of assignment not really an lvalue warnings on the 2 lines inside the while loops. Can anyone break down those lines? a cast then an increment? What is a simplier way to write that? What does the error mean?

    Read the article

  • Overloading assignment operator in C#

    - by Carson Myers
    I know the = operator can't be overloaded, but there must be a way to do what I want here: I'm just creating classes to represent quantitative units, since I'm doing a bit of physics. Apparently I can't just inherit from a primitive, but I want my classes to behave exactly like primitives -- I just want them typed differently. So I'd be able to go, Velocity ms = 0; ms = 17.4; ms += 9.8; etc. I'm not sure how to do this. I figured I'd just write some classes like so: class Power { private Double Value { get; set; } //operator overloads for +, -, /, *, =, etc } But apparently I can't overload the assignment operator. Is there any way I can get this behavior?

    Read the article

  • assignment from incompatible pointer type

    - by Hristo
    I have set up the following struct: typedef struct _thread_node_t { pthread_t thread; struct thread_node_t *next; } thread_node_t; ... and then I have defined: // create thread to for incoming connection thread_node_t *thread_node = (thread_node_t*) malloc(sizeof(thread_node_t)); pthread_create(&(thread_node->thread), NULL, client_thread, &csFD); thread_node->next = thread_arr; // assignment from incompatible pointer type thread_arr = thread_node; where thread_arr is thread_node_t *thread_arr = NULL; I don't understand why the compiler is complaining. Maybe I'm misunderstanding something.

    Read the article

  • Sending variable to $.getScript

    - by oshirowanen
    Is it possible to send a variable to the script loaded using $.getScript? At the moment I have: $.getScript( "js/my_script.js", function() { // do something here after script has loaded }); But I want to send a variable to the loaded script. Is this possible, if yes, how? For example // this is a variable set outside of the script loaded via `$.getScript` var my_variable = 1 // how do I get that variable sent to `my_script.js` $.getScript( "my_script.js", function() { // do something here after script has loaded });

    Read the article

  • C Programming - My program is good enough for my assignment but I know its not good

    - by Joe
    Hi there I'm just starting an assignment for uni and it's raised a question for me. I don't understand how to return a string from a function without having a memory leak. char* trim(char* line) { int start = 0; int end = strlen(line) - 1; /* find the start position of the string */ while(isspace(line[start]) != 0) { start++; } //printf("start is %d\n", start); /* find the position end of the string */ while(isspace(line[end]) != 0) { end--; } //printf("end is %d\n", end); /* calculate string length and add 1 for the sentinel */ int len = end - start + 2; /* initialise char array to len and read in characters */ int i; char* trimmed = calloc(sizeof(char), len); for(i = 0; i < (len - 1); i++) { trimmed[i] = line[start + i]; } trimmed[len - 1] = '\0'; return trimmed; } as you can see I am returning a pointer to char which is an array. I found that if I tried to make the 'trimmed' array by something like: char trimmed[len]; then the compiler would throw up a message saying that a constant was expected on this line. I assume this meant that for some reason you can't use variables as the array length when initialising an array, although something tells me that can't be right. So instead I made my array by allocating some memory to a char pointer. I understand that this function is probably waaaaay sub-optimal for what it is trying to do, but what I really want to know is: 1. Can you normally initialise an array using a variable to declare the length like: char trimmed[len]; ? 2. If I had an array that was of that type (char trimmed[]) would it have the same return type as a pointer to char (ie char*). 3. If I make my array by callocing some memory and allocating it to a char pointer, how do I free this memory. It seems to me that once I have returned this array, I can't access it to free it as it is a local variable. Many thanks in advance Joe

    Read the article

  • C++ assignment operators dynamic arrays

    - by user2905445
    First off i know the multiplying part is wrong but i have some questions about the code. 1. When i am overloading my operator+ i print out the matrix using cout << *this then right after i return *this and when i do a+b on matix a and matix b it doesnt give me the same thing this is very confusing. 2. When i make matrix c down in my main i cant use my default constructor for some reason because when i go to set it = using my assignment operator overloaded function it gives me an error saying "expression must be a modifiable value. although using my constructor that sets the row and column numbers is the same as my default constructor using (0,0). 3. My assignment operator= function uses a copy constructor to make a new matrix using the values on the right hand side of the equal sign and when i print out c it doesn't give me anything Any help would be great this is my hw for a algorithm class which i still need to do the algorithm for the multiplying matrices but i need to solve these issues first and im having a lot of trouble please help. //Programmer: Eric Oudin //Date: 10/21/2013 //Description: Working with matricies #include <iostream> using namespace std; class matrixType { public: friend ostream& operator<<(ostream&, const matrixType&); const matrixType& operator*(const matrixType&); matrixType& operator+(const matrixType&); matrixType& operator-(const matrixType&); const matrixType& operator=(const matrixType&); void fillMatrix(); matrixType(); matrixType(int, int); matrixType(const matrixType&); ~matrixType(); private: int **matrix; int rowSize; int columnSize; }; ostream& operator<< (ostream& osObject, const matrixType& matrix) { osObject << endl; for (int i=0;i<matrix.rowSize;i++) { for (int j=0;j<matrix.columnSize;j++) { osObject << matrix.matrix[i][j] <<", "; } osObject << endl; } return osObject; } const matrixType& matrixType::operator=(const matrixType& matrixRight) { matrixType temp(matrixRight); cout << temp; return temp; } const matrixType& matrixType::operator*(const matrixType& matrixRight) { matrixType temp(rowSize*matrixRight.columnSize, columnSize*matrixRight.rowSize); if(rowSize == matrixRight.columnSize) { for (int i=0;i<rowSize;i++) { for (int j=0;j<columnSize;j++) { temp.matrix[i][j] = matrix[i][j] * matrixRight.matrix[i][j]; } } } else { cout << "Cannot multiply matricies that have different size rows from the others columns." << endl; } return temp; } matrixType& matrixType::operator+(const matrixType& matrixRight) { if(rowSize == matrixRight.rowSize && columnSize == matrixRight.columnSize) { for (int i=0;i<rowSize;i++) { for (int j=0;j<columnSize;j++) { matrix[i][j] += matrixRight.matrix[i][j]; } } } else { cout << "Cannot add matricies that are different sizes." << endl; } cout << *this; return *this; } matrixType& matrixType::operator-(const matrixType& matrixRight) { matrixType temp(rowSize, columnSize); if(rowSize == matrixRight.rowSize && columnSize == matrixRight.columnSize) { for (int i=0;i<rowSize;i++) { for (int j=0;j<columnSize;j++) { matrix[i][j] -= matrixRight.matrix[i][j]; } } } else { cout << "Cannot subtract matricies that are different sizes." << endl; } return *this; } void matrixType::fillMatrix() { for (int i=0;i<rowSize;i++) { for (int j=0;j<columnSize;j++) { cout << "Enter the matix number at (" << i << "," << j << "):"; cin >> matrix[i][j]; } } } matrixType::matrixType() { rowSize=0; columnSize=0; matrix = new int*[rowSize]; for (int i=0; i < rowSize; i++) { matrix[i] = new int[columnSize]; } } matrixType::matrixType(int setRows, int setColumns) { rowSize=setRows; columnSize=setColumns; matrix = new int*[rowSize]; for (int i=0; i < rowSize; i++) { matrix[i] = new int[columnSize]; } } matrixType::matrixType(const matrixType& otherMatrix) { rowSize=otherMatrix.rowSize; columnSize=otherMatrix.columnSize; matrix = new int*[rowSize]; for (int i = 0; i < rowSize; i++) { for (int j = 0; j < columnSize; j++) { matrix[i]=new int[columnSize]; matrix[i][j]=otherMatrix.matrix[i][j]; } } } matrixType::~matrixType() { delete [] matrix; } int main() { matrixType a(2,2); matrixType b(2,2); matrixType c(0,0); cout << "fill matrix a:"<< endl;; a.fillMatrix(); cout << "fill matrix b:"<< endl;; b.fillMatrix(); cout << a; cout << b; c = a+b; cout <<"matrix a + matrix b =" << c; system("PAUSE"); return 0; }

    Read the article

  • Allowed characters in linux environment variable names

    - by Christian Semrau
    What characters are allowed in linux environment variable names? My cursory search of man pages and the web did only produce information about how to work with variables, but not which names are allowed. I have a Java program that requires an defined environment variable containing a dot, like com.example.fancyproperty. With Windows I can set that variable, but I had no luck setting it in linux (tried in SuSE and Ubuntu). Is that variable name even allowed?

    Read the article

  • How to approach copying objects with smart pointers as class attributes?

    - by tomislav-maric
    From the boost library documentation I read this: Conceptually, smart pointers are seen as owning the object pointed to, and thus responsible for deletion of the object when it is no longer needed. I have a very simple problem: I want to use RAII for pointer attributes of a class that is Copyable and Assignable. The copy and assignment operations should be deep: every object should have its own copy of the actual data. Also, RTTI needs to be available for the attributes (their type may also be determined at runtime). Should I be searching for an implementation of a Copyable smart pointer (the data are small, so I don't need Copy on Write pointers), or do I delegate the copy operation to the copy constructors of my objects as shown in this answer? Which smart pointer do I choose for simple RAII of a class that is copyable and assignable? (I'm thinking that the unique_ptr with delegated copy/assignment operations to the class copy constructor and assignment operator would make a proper choice, but I am not sure) Here's a pseudocode for the problem using raw pointers, it's just a problem description, not a running C++ code: // Operation interface class ModelOperation { public: virtual void operate = (); }; // Implementation of an operation called Special class SpecialModelOperation : public ModelOperation { private: // Private attributes are present here in a real implementation. public: // Implement operation void operate () {}; }; // All operations conform to ModelOperation interface // These are possible operation names: // class MoreSpecialOperation; // class DifferentOperation; // Concrete model with different operations class MyModel { private: ModelOperation* firstOperation_; ModelOperation* secondOperation_; public: MyModel() : firstOperation_(0), secondOperation_(0) { // Forgetting about run-time type definition from input files here. firstOperation_ = new MoreSpecialOperation(); secondOperation_ = new DifferentOperation(); } void operate() { firstOperation_->operate(); secondOperation_->operate(); } ~MyModel() { delete firstOperation_; firstOperation_ = 0; delete secondOperation_; secondOperation_ = 0; } }; int main() { MyModel modelOne; // Some internal scope { // I want modelTwo to have its own set of copied, not referenced // operations, and at the same time I need RAII to work for it, // as soon as it goes out of scope. MyModel modelTwo (modelOne); } return 0; }

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >