Search Results

Search found 43467 results on 1739 pages for 'member function pointers'.

Page 10/1739 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • Using pointers to adjust global objects in objective-c

    - by Rob
    Ok, so I am working with two sets of data that are extremely similar, and at the same time, these data sets are both global NSMutableArrays within the object. data_set_one = [[NSMutableArray alloc] init]; data_set_two = [[NSMutableArray alloc] init]; Two new NSMutableArrays are loaded, which need to be added to the old, existing data. These Arrays are also global. xml_dataset_one = [[NSMutableArray alloc] init]; xml_dataset_two = [[NSMutableArray alloc] init]; To reduce code duplication (and because these data sets are so similar) I wrote a void method within the class to handle the data combination process for both Arrays: -(void)constructData:(NSMutableArray *)data fromDownloadArray:(NSMutableArray *)down withMatchSelector:(NSString *)sel_str Now, I have a decent understanding of object oriented programming, so I was thinking that if I were to invoke the method with the global Arrays in the data like so... [self constructData:data_set_one fromDownloadArray:xml_dataset_one withMatchSelector:@"id"]; Then the global NSMutableArrays (data_set_one) would reflect the changes that happen to "array" within the method. Sadly, this is not the case, data_set_one doesn't reflect the changes (ex: new objects within the Array) outside of the method. Here is a code snippet of the problem // data_set_one is empty // xml_dataset_one has a few objects [constructData:(NSMutableArray *)data_set_one fromDownloadArray:(NSMutableArray *)xml_dataset_one withMatchSelector:(NSString *)@"id"]; // data_set_one should now be xml_dataset_one, but when echoed to screen, it appears to remain empty And here is the gist of the code for the method, any help is appreciated. -(void)constructData:(NSMutableArray *)data fromDownloadArray:(NSMutableArray *)down withMatchSelector:(NSString *)sel_str { if ([data count] == 0) { data = down; // set data equal to downloaded data } else if ([down count] == 0) { // download yields no results, do nothing } else { // combine the two arrays here } } This project is not ARC enabled. Thanks for the help guys! Rob

    Read the article

  • For-Each and Pointers in Java

    - by John
    Ok, so I'm tyring to iterate through an ArrayList and remove a specefic element. However, I am having some trouble using the For-Each like structure. When I run the following code: ArrayList<String> arr = new ArrayList<String>(); //... fill with some values (doesn't really matter) for(String t : arr) { t = " some other value "; //hoping this would change the actual array } for(String t : arr) { System.out.println(t); //however, I still get the same array here } My question in, how can I make 't' a pointer to 'arr' so that I am able to change the values in a for-each loop? I know I could loop through the ArrayList using a different structure, but this one looks so clean and readable, it would just be nice to be able to make 't' a pointer. All comments are appreciated! Even if you say I should just suck it up and use a different construct.

    Read the article

  • C++: Trouble with Pointers, loop variables, and structs

    - by Rosarch
    Consider the following example: #include <iostream> #include <sstream> #include <vector> #include <wchar.h> #include <stdlib.h> using namespace std; struct odp { int f; wchar_t* pstr; }; int main() { vector<odp> vec; ostringstream ss; wchar_t base[5]; wcscpy_s(base, L"1234"); for (int i = 0; i < 4; i++) { odp foo; foo.f = i; wchar_t loopStr[1]; foo.pstr = loopStr; // wchar_t* = wchar_t ? Why does this work? foo.pstr[0] = base[i]; vec.push_back(foo); } for (vector<odp>::iterator iter = vec.begin(); iter != vec.end(); iter++) { cout << "Vec contains: " << iter->f << ", " << *(iter->pstr) << endl; } } This produces: Vec contains: 0, 52 Vec contains: 1, 52 Vec contains: 2, 52 Vec contains: 3, 52 I would hope that each time, iter->f and iter->pstr would yield a different result. Unfortunately, iter->pstr is always the same. My suspicion is that each time through the loop, a new loopStr is created. Instead of copying it into the struct, I'm only copying a pointer. The location that the pointer writes to is getting overwritten. How can I avoid this? Is it possible to solve this problem without allocating memory on the heap?

    Read the article

  • C++ containers on classes, returning pointers

    - by otneil
    Hello, I'm having some trouble to find the best way to accomplish what I have in mind due to my inexperience. I have a class where I need to a vector of objects. So my first question will be: is there any problem having this: vector< AnyType container* and then on the constructor initialize it with new (and deleting it on the destructor)? Another question is: if this vector is going to store objects, shouldn't it be more like vector< AnyTipe* so they could be dynamically created? In that case how would I return an object from a method and how to avoid memory leaks (trying to use only STL)?

    Read the article

  • Pointers and Addresses in C

    - by Mohit
    #include "stdio.h" main() { int i=3,*x; float j=1.5,*y; char k='c',*z; x=&i; y=&j; z=&k; printf("\nAddress of x= %u",x); printf("\nAddress of y= %u",y); printf("\nAddress of z= %u",z); x++; y++;y++;y++;y++; z++; printf("\nNew Address of x= %u",x); printf("\nNew Address of y= %u",y); printf("\nNew Address of z= %u",z); printf("\nNew Value of i= %d",i); printf("\nNew Value of j= %f",j); printf("\nNew Value of k= %c\n",k); } Output: Address of x= 3219901868 Address of y= 3219901860 Address of z= 3219901875 New Address of x= 3219901872 New Address of y= 3219901876 New Address of z= 3219901876 New Value of i= 3 New Value of j= 1.500000 New Value of k= c The new address of variable y and z are same. How can two variables have same address and et have different values? Note: I used gcc compiler on Ubuntu 9.04

    Read the article

  • Sort a list of pointers.

    - by YuppieNetworking
    Hello all, Once again I find myself failing at some really simple task in C++. Sometimes I wish I could de-learn all I know from OO in java, since my problems usually start by thinking like Java. Anyways, I have a std::list<BaseObject*> that I want to sort. Let's say that BaseObject is: class BaseObject { protected: int id; public: BaseObject(int i) : id(i) {}; virtual ~BaseObject() {}; }; I can sort the list of pointer to BaseObject with a comparator struct: struct Comparator { bool operator()(const BaseObject* o1, const BaseObject* o2) const { return o1->id < o2->id; } }; And it would look like this: std::list<BaseObject*> mylist; mylist.push_back(new BaseObject(1)); mylist.push_back(new BaseObject(2)); // ... mylist.sort(Comparator()); // intentionally omitted deletes and exception handling Until here, everything is a-ok. However, I introduced some derived classes: class Child : public BaseObject { protected: int var; public: Child(int id1, int n) : BaseObject(id1), var(n) {}; virtual ~Child() {}; }; class GrandChild : public Child { public: GrandChild(int id1, int n) : Child(id1,n) {}; virtual ~GrandChild() {}; }; So now I would like to sort following the following rules: For any Child object c and BaseObject b, b<c To compare BaseObject objects, use its ids, as before. To compare Child objects, compare its vars. If they are equal, fallback to rule 2. GrandChild objects should fallback to the Child behavior (rule 3). I initially thought that I could probably do some casts in Comparator. However, this casts away constness. Then I thought that probably I could compare typeids, but then everything looked messy and it is not even correct. How could I implement this sort, still using list<BaseObject*>::sort ? Thank you

    Read the article

  • Are pointers primitive types in C++?

    - by Space_C0wb0y
    I was wondering about the last constructor for std::string mentioned here. It says: template<class InputIterator> string (InputIterator begin, InputIterator end); If InputIterator is an integral type, behaves as the sixth constructor version (the one right above this) by typecasting begin and end to call it: string(static_cast<size_t>(begin),static_cast<char>(end)); In any other case, the parameters are taken as iterators, and the content is initialized with the values of the elements that go from the element referred by iterator begin to the element right before the one referred by iterator end. So what does that mean if InputIterator is a char * ?

    Read the article

  • C++ Array of pointers: delete or delete []?

    - by Jasper
    Cosider the following code: class Foo { Monster* monsters[6]; Foo() { for (int i = 0; i < 6; i++) { monsters[i] = new Monster(); } } virtual ~Foo(); } What is the correct destructor? this: Foo::~Foo() { delete [] monsters; } or this: Foo::~Foo() { for (int i = 0; i < 6; i++) { delete monsters[i]; } } I currently have the uppermost constructor and everything is working okey, but of course I cannot see if it happens to be leaking... Personally, I think the second version is much more logical considering what I am doing. Anyway, what is the "proper" way to do this?

    Read the article

  • C++ pointers on example

    - by terence6
    I have a sample code : #include <iostream> #include <conio.h> using namespace std; int main () { int firstvalue = 5, secondvalue = 15; int * p1, * p2; p1 = &firstvalue; p2 = &secondvalue; cout << "1.p1: " << p1 << ", p2: " << p2 << endl; cout << "1.*p1: " << *p1 << ", *p2: " << *p2 << endl; *p1 = 10; cout << "2.p1: " << p1 << ", p2: " << p2 << endl; cout << "2.*p1: " << *p1 << ", *p2: " << *p2 << endl; *p2 = *p1; cout << "3.p1: " << p1 << ", p2: " << p2 << endl; cout << "3.*p1: " << *p1 << ", *p2: " << *p2 << endl; p1 = p2; cout << "4.p1: " << p1 << ", p2: " << p2 << endl; cout << "4.*p1: " << *p1 << ", *p2: " << *p2 << endl; *p1 = 20; cout << "5.p1: " << p1 << ", p2: " << p2 << endl; cout << "5.*p1: " << *p1 << ", *p2: " << *p2 << endl; cout << "firstvalue is " << firstvalue << endl; cout << "secondvalue is " << secondvalue << endl; cout << "firstvalue is " << &firstvalue << endl; cout << "secondvalue is " << &secondvalue << endl; getch(); return 0; } And here's the output : 1.p1: 0041FB40, p2: 0041FB34 1.*p1: 5, *p2: 15 2.p1: 0041FB40, p2: 0041FB34 2.*p1: 10, *p2: 15 3.p1: 0041FB40, p2: 0041FB34 3.*p1: 10, *p2: 10 4.p1: 0041FB34, p2: 0041FB34 4.*p1: 10, *p2: 10 5.p1: 0041FB34, p2: 0041FB34 5.*p1: 20, *p2: 20 firstvalue is 10 secondvalue is 20 firstvalue is 0041FB40 secondvalue is 0041FB34 What is copied in the line "p1 = p2" ? Does p1 become reference to p2 or does it work in different way ?

    Read the article

  • C++ class member functions instantiated by traits

    - by Jive Dadson
    I am reluctant to say I can't figure this out, but I can't figure this out. I've googled and searched Stack Overflow, and come up empty. The abstract, and possibly overly vague form of the question is, how can I use the traits-pattern to instantiate non-virtual member functions? The question came up while modernizing a set of multivariate function optimizers that I wrote more than 10 years ago. The optimizers all operate by selecting a straight-line path through the parameter space away from the current best point (the "update"), then finding a better point on that line (the "line search"), then testing for the "done" condition, and if not done, iterating. There are different methods for doing the update, the line-search, and conceivably for the done test, and other things. Mix and match. Different update formulae require different state-variable data. For example, the LMQN update requires a vector, and the BFGS update requires a matrix. If evaluating gradients is cheap, the line-search should do so. If not, it should use function evaluations only. Some methods require more accurate line-searches than others. Those are just some examples. The original version instantiates several of the combinations by means of virtual functions. Some traits are selected by setting mode bits that are tested at runtime. Yuck. It would be trivial to define the traits with #define's and the member functions with #ifdef's and macros. But that's so twenty years ago. It bugs me that I cannot figure out a whiz-bang modern way. If there were only one trait that varied, I could use the curiously recurring template pattern. But I see no way to extend that to arbitrary combinations of traits. I tried doing it using boost::enable_if, etc.. The specialized state information was easy. I managed to get the functions done, but only by resorting to non-friend external functions that have the this-pointer as a parameter. I never even figured out how to make the functions friends, much less member functions. The compiler (VC++ 2008) always complained that things didn't match. I would yell, "SFINAE, you moron!" but the moron is probably me. Perhaps tag-dispatch is the key. I haven't gotten very deeply into that. Surely it's possible, right? If so, what is best practice?

    Read the article

  • Pointers in For loops

    - by Bobby
    Quick question: I am a C# guy debugging a C++ app so I am not used to memory management. In the following code: for(int i = 0; i < TlmMsgDB.CMTGetTelemMsgDBCount(); i++) { CMTTelemetryMsgCls* telm = TlmMsgDB.CMTGetTelemetryMsg(i); CMT_SINT32_Tdef id = telm->CMTGetPackingMapID(); ManualScheduleTables.SetManualMsg(i,id); ManualScheduleTables.SetManExec(i,false); } Am I leaking memory every iteration b/c of CMTTelemetryMsgCls* telm = TlmMsgDB.CMTGetTelemetryMsg(i);? The "CMTGetTelemetryMsg(int)" method returns a pointer. Do I have to "delete telm;" at the end of each iteration?

    Read the article

  • typedef to store pointers in C

    - by seriouslion
    The Size of pointer depends on the arch of the machine. So sizeof(int*)=sizeof(int) or sizeof(int*)=sizeof(long int) I want to have a custom data type which is either int or long int depending on the size of pointer. I tried to use macro #if, but the condition for macros does not allow sizeof operator. Also when using if-else, typedef is limited to the scope of if. if((sizeof(int)==sizeof(int *)){ typedef int ptrtype; } else{ typedef long int ptrtype; } //ptrtype not avialble here Is there any way to define ptrtype globally?

    Read the article

  • Assign pointers in objective C

    - by Tattat
    -(id)setBigObject:(BigObject *)abc{ self.wl = abc; abc.smallObject = self.smallObject; } I have a abc, which is a big Object, when the user pass the bigObject, abc. I assign to my wl value, so , I write "self.wl = abc;", but I want my smallObject assign to the abc's smallObject, so, I do "abc.smallObject = self.smallObject; " So, when I edit the smallObject in self, it will also changed in the abc's also? Am I right?

    Read the article

  • Function pointers usage

    - by chaitanyavarma
    Hi All, Why these two codes give the same output, Case 1: #include <stdio.h> typedef void (*mycall) (int a ,int b); void addme(int a,int b); void mulme(int a,int b); void subme(int a,int b); main() { mycall x[10]; x[0] = &addme; x[1] = &subme; x[2] = &mulme; (x[0])(5,2); (x[1])(5,2); (x[2])(5,2); } void addme(int a, int b) { printf("the value is %d\n",(a+b)); } void mulme(int a, int b) { printf("the value is %d\n",(a*b)); } void subme(int a, int b) { printf("the value is %d\n",(a-b)); } Output: the value is 7 the value is 3 the value is 10 Case 2 : #include <stdio.h> typedef void (*mycall) (int a ,int b); void addme(int a,int b); void mulme(int a,int b); void subme(int a,int b); main() { mycall x[10]; x[0] = &addme; x[1] = &subme; x[2] = &mulme; (*x[0])(5,2); (*x[1])(5,2); (*x[2])(5,2); } void addme(int a, int b) { printf("the value is %d\n",(a+b)); } void mulme(int a, int b) { printf("the value is %d\n",(a*b)); } void subme(int a, int b) { printf("the value is %d\n",(a-b)); } Output: the value is 7 the value is 3 the value is 10

    Read the article

  • Function pointers uasage

    - by chaitanyavarma
    Hi All, Why these two codes give the same output, Case - 1: #include <stdio.h> typedef void (*mycall) (int a ,int b); void addme(int a,int b); void mulme(int a,int b); void subme(int a,int b); main() { mycall x[10]; x[0] = &addme; x[1] = &subme; x[2] = &mulme; (x[0])(5,2); (x[1])(5,2); (x[2])(5,2); } void addme(int a, int b) { printf("the value is %d\n",(a+b)); } void mulme(int a, int b) { printf("the value is %d\n",(a*b)); } void subme(int a, int b) { printf("the value is %d\n",(a-b)); } Output: the value is 7 the value is 3 the value is 10 Case -2 : #include <stdio.h> typedef void (*mycall) (int a ,int b); void addme(int a,int b); void mulme(int a,int b); void subme(int a,int b); main() { mycall x[10]; x[0] = &addme; x[1] = &subme; x[2] = &mulme; (*x[0])(5,2); (*x[1])(5,2); (*x[2])(5,2); } void addme(int a, int b) { printf("the value is %d\n",(a+b)); } void mulme(int a, int b) { printf("the value is %d\n",(a*b)); } void subme(int a, int b) { printf("the value is %d\n",(a-b)); } Output: the value is 7 the value is 3 the value is 10

    Read the article

  • Pointers in C with binary file

    - by darkie15
    Hi All, I am reading the contents of the file using fread into an char array. But I am not sure why it is not getting printed in the output. Here is the code: void getInfo(FILE* inputFile) { char chunk[4]; int liIndex; for (liIndex = 0 ; liIndex < 4 ; liIndex++) { fread(chunk, sizeof(char), 4, inputFile); } printf("\n chunk %s", chunk); } Output prints nothing at all. Where am I going wrong? Regards , darkie

    Read the article

  • Proper way to reassign pointers in c++

    - by user272689
    I want to make sure i have these basic ideas correct before moving on (I am coming from a Java/Python background). I have been searching the net, but haven't found a concrete answer to this question yet. When you reassign a pointer to a new object, do you have to call delete on the old object first to avoid a memory leak? My intuition is telling me yes, but i want a concrete answer before moving on. For example, let say you had a class that stored a pointer to a string class MyClass { private: std::string *str; public: MyClass (const std::string &_str) { str=new std::string(_str); } void ChangeString(const std::string &_str) { // I am wondering if this is correct? delete str; str = new std::string(_str) /* * or could you simply do it like: * str = _str; */ } .... In the ChangeString method, which would be correct? I think i am getting hung up on if you dont use the new keyword for the second way, it will still compile and run like you expected. Does this just overwrite the data that this pointer points to? Or does it do something else? Any advice would be greatly appricated :D

    Read the article

  • Function keys for ASUS n56vm not working

    - by Lars
    i have installed Ubuntu 12.10 (64bits) (3.5.0-18 kernel) on an ASUS N56VM. Most fn+key are working except for: brightness keys (fn+f5/fn+f6) don't work. fn+c - gamma keys fc+v - camera fn+space - toggle speed. I really like, at least, to have the brightness keys working. Can you help? Best Regards $ dmesg | grep -i asus [ 0.000000] DMI: ASUSTeK COMPUTER INC. N56VM/N56VM, BIOS N56VM.206 04/13/2012 [ 0.000000] ACPI: RSDP 00000000cafcc000 00024 (v02 _ASUS_) [ 0.000000] ACPI: XSDT 00000000cafcc078 00074 (v01 _ASUS_ Notebook 01072009 AMI 00010013) [ 0.000000] ACPI: FACP 00000000cafdf858 000F4 (v04 _ASUS_ Notebook 01072009 AMI 00010013) [ 0.000000] ACPI: DSDT 00000000cafcc188 136CA (v02 _ASUS_ Notebook 00000013 INTL 20091112) [ 0.000000] ACPI: APIC 00000000cafdf950 00092 (v03 _ASUS_ Notebook 01072009 AMI 00010013) [ 0.000000] ACPI: FPDT 00000000cafdf9e8 00044 (v01 _ASUS_ Notebook 01072009 AMI 00010013) [ 0.000000] ACPI: ECDT 00000000cafdfa30 000C1 (v01 _ASUS_ Notebook 01072009 AMI. 00000005) [ 0.000000] ACPI: MCFG 00000000cafdfaf8 0003C (v01 _ASUS_ Notebook 01072009 MSFT 00000097) [ 0.000000] ACPI: SLIC 00000000cafdfb38 00176 (v01 _ASUS_ Notebook 01072009 ASUS 00000001) [ 0.000000] ACPI: HPET 00000000cafdfcb0 00038 (v01 _ASUS_ Notebook 01072009 AMI. 00000005) [ 0.000000] ACPI: BGRT 00000000cafe1090 00038 (v00 _ASUS_ Notebook 01072009 ASUS 00010013) [ 9.670500] asus_wmi: ASUS WMI generic driver loaded [ 9.671627] asus_wmi: Initialization: 0x1asus_wmi: BIOS WMI version: 7.9 [ 9.671673] asus_wmi: SFUN value: 0x6a0877<6>[ 9.672086] input: Asus WMI hotkeys as /devices/platform/asus-nb-wmi/input/input4 [ 9.732438] Registered led device: asus::kbd_backlight [ 9.733242] asus_wmi: Backlight controlled by ACPI video driver

    Read the article

  • ASP.NET – Function to Fill Month, Date and Year into Dropdown lists

    - by SAMIR BHOGAYTA
    public void fillMonthList(DropDownList ddlList) { ddlList.Items.Add(new ListItem("Month", "Month")); ddlList.SelectedIndex = 0; DateTime month = Convert.ToDateTime("1/1/2000"); for (int intLoop = 0; intLoop { DateTime NextMont = month.AddMonths(intLoop); //ddlList.Items.Add(new ListItem(NextMont.ToString("MMMM"), NextMont.Month.ToString())); ddlList.Items.Add(new ListItem(NextMont.ToString("MMMM"), NextMont.ToString("MMMM"))); } } public void fillDayList(DropDownList ddlList) { ddlList.Items.Add(new ListItem("Day", "Day")); ddlList.SelectedIndex = 0; int totalDays = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); for (int intLoop = 1; intLoop { ddlList.Items.Add(new ListItem(intLoop.ToString(), intLoop.ToString())); } } public void fillYearList(DropDownList ddlList) { ddlList.Items.Add(new ListItem("Year", "Year")); ddlList.SelectedIndex = 0; int intYearName = 1900; for (int intLoop = intYearName; intLoop { ddlList.Items.Add(new ListItem(intLoop.ToString(), intLoop.ToString())); } }

    Read the article

  • C - Complicated pointer declarations - help understanding

    - by Emmel
    In my burgeoning new self-education in the C language, I've come across a set of declarations that I do not understand how to read. I'd love for someone to break these down. I'll explain at the bottom where I got these examples from. 1. char (*(*x())[])() "x: function returning pointer to array[] of pointer to function returning char" - huh? 2. char (*(*x[3])())[5] "x: array[3] of pointer to function returning pointer to array[5] of char" - come again? 3. char **argv This I understand. "Pointer to pointer to char." But what I don't understand is -- what's the use case for a pointer to a pointer? Follow-up question: does anyone every use declarations this complex or is this just academic fun on the part of the authors of the examples I got this from? These examples are from section 5.12 of the K&R book. This is the first time I'm genuinely stumped by an explanation, in an otherwise well-written classic. Thanks.

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >