Search Results

Search found 2566 results on 103 pages for 'struct'.

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

  • [C++] Can all/any struct assignment operator be Overloaded? (and specifically struct tm = sql::Resu

    - by Luke Mcneice
    Hi all, Generally, i was wondering if there was any exceptions of types that cant have thier assignment operator overloaded. Specifically, I'm wanting to overload the assignment operator of a tm struct, (time.h) so i can assign a sql::ResultSet to it. I have already have the conversion logic: sscanf(sqlresult->getString("StoredAt").c_str(),"%d-%d-%d %d:%d:%d",&TempTimeStruct->tm_year,&TempTimeStruct->tm_mon,&TempTimeStruct->tm_mday,&TempTimeStruct->tm_hour,&TempTimeStruct->tm_min,&TempTimeStruct->tm_sec); //populating the struct I tried the overload with this: tm& tm::operator=(sql::ResultSet & results) { //CODE return *this; } however VS08 reports: error C2511: 'tm &tm::operator =(sql::ResultSet &)' : overloaded member function not found in 'tm'

    Read the article

  • Unmanaged Struct Instance in Managed Class

    - by HeHasMoments
    Hi, I've got a fairly specific problem i've been struggling with for a couple of days. I'm using a native C++, one of the methods takes a ptr to a struct containing fixed size char arrays. e.g. struct userData { char data1[10]; char data2[10]; }; method: short AddItem(long id, userData* data); I'm trying to call to call this from Managed VC++ but I need to have an instance of userData I can keep hold of in my managed class. Can anyone help with how to achieve this? Thanks

    Read the article

  • how to print a char from struct

    - by make
    Hi Could someone please tell us to print a char when receiving data as a struct? Here is an example: ... struct rcv{ int x1; float x2; char *x3; }; rcv data_rcv; ... if (recv(socket, &data_rcv, sizeof(data_rcv), 0) < 0) printf("recv() failed"); ... printf("x1 = %d\n", data_rcv.x1); printf("x2 = %f\n", data_rcv.x2); printf("x3 = %s\n", data_rcv.x3); // it doesn't print anything, why? ... Thanks for your replies-

    Read the article

  • Constructor/Destructor involving a class and a struct

    - by Bogdan Maier
    I am working on a program and need to make an array of objects, specifically I have a 31x1 array where each position is an object, (each object is basically built out of 6 ints). Here is what I have but something is wrong and i could use some help thank you. 31x1 struct header" const int days=31; struct Arr{ int days; int *M; }; typedef Arr* Array; 31x1 matrix constructor: void constr(){ int *M; M = new Expe[31]; // Expe is the class class header: class Expe { private: //0-HouseKeeping, 1-Food, 2-Transport, 3-Clothing, 4-TelNet, 5-others int *obj; } Class object constructor: Expe::Expe() { this->obj=new int[6]; } help please... because i`m pretty lost.

    Read the article

  • why arrayfun does NOT improve my struct array operation performance

    - by HaveF
    here is the input data: % @param Landmarks: % Landmarks should be 1*m struct. % m is the number of training set. % Landmark(i).data is a n*2 matrix old function: function Landmarks=CenterOfGravity(Landmarks) % align center of gravity for i=1 : length(Landmarks) Landmarks(i).data=Landmarks(i).data - ones(size(Landmarks(i).data,1),1)... *mean(Landmarks(i).data); end end new function which use arrayfun: function [Landmarks] = center_to_gravity(Landmarks) Landmarks = arrayfun(@(struct_data)... struct('data', struct_data.data - repmat(mean(struct_data.data), [size(struct_data.data, 1), 1]))... ,Landmarks); end %function center_to_gravity when using profiler, I find the usage of time is NOT what I expected: Function Total Time Self Time* CenterOfGravity 0.011s 0.004 s center_to_gravity 0.029s 0.001 s Can someone tell me why? BTW...I can't add "arrayfun" as a new tag for my reputation.

    Read the article

  • Build comma seperated string from the struct in C#

    - by acadia
    Hello, I have the following struct in C# class public struct Employee { public const string EMPID = "EMP_ID"; public const string FName = "FIRST_NAME"; public const string LNAME = "LAST_NAME"; public const string DEPTID = "DEPT_ID"; } Is there an easy way to build a string as follows const string mainquery="INSERT INTO EMP(EMP_ID,FIRST_NAME,LAST_NAME,DEPT_ID) VALUES(:EMP_ID,:FIRST_NAME,:LAST_NAME,:DEPT_ID)" Instead of doing as follows and then concatenating it. const string EMP_COLS= EMPLOYEE.EMPID + "," + EMPLOYEE.FNAME + "," + EMPLOYEE.LNAME + "," + EMPLOYEE.DEPTID; const string EMP_Values= EMPLOYEE.EMPID + ":" + EMPLOYEE.FNAME + ":" + EMPLOYEE.LNAME + ":" + EMPLOYEE.DEPTID;

    Read the article

  • C++: Delete a struct?

    - by Rosarch
    I have a struct that contains pointers: struct foo { char* f; int* d; wchar* m; } I have a vector of shared pointers to these structs: vector<shared_ptr<foo>> vec; vec is allocated on the stack. When it passes out of scope at the end of the method, its destructor will be called. (Right?) That will in turn call the destructor of each element in the vector. (Right?) Does calling delete foo delete just the pointers such as foo.f, or does it actually free the memory from the heap?

    Read the article

  • Scheme - What is wrong with my attempt to extend this declaration?

    - by CppLearner
    This is a homework question. Question My attempt (the whole file): http://pastebin.com/vt3Q3dqs If you search let var = exp1 in body, that's the function I need to extend according to the question. When I test the sample code above, I get an error apply-env: No binding for y (eval "let x = 30 in let x = -(x,1) y = -(x,2) in -(x,y)") ; The following is execution log The-next-two-lines-shows-var-and-exp1 (x) (#(struct:const-exp 30)) diff-exp #(struct:var-exp x) #(struct:const-exp 1) diff-exp #(struct:var-exp x) #(struct:const-exp 2) The-next-two-lines-shows-var-and-exp1 (x y) (#(struct:diff-exp #(struct:var-exp x) #(struct:const-exp 1)) #(struct:diff-exp #(struct:var-exp x) #(struct:const-exp 2))) diff-exp #(struct:var-exp x) #(struct:var-exp y) As you can see, when the interperter reads the last line -(x,y) it complains because there is no binding. What did I do wrong? I know this is really long language, but if anyone can kindly lead me to the right direction would be really really nice. Thank you!

    Read the article

  • I have a Segmentation fault (core dumped) when using strcpy, malloc, and struct

    - by malsh002
    Okay, when I run this code, I have a segmentation fault #include<stdio.h> #include<stdlib.h> #include<string.h> #define MAX 64 struct example { char *name; }; int main() { struct example *s = malloc (MAX); strcpy(s->name ,"Hello World!!"); return !printf("%s\n", s->name); } the terminal output: alshamlan@alshamlan-VGN-CR520E:/tmp/interview$ make q1 cc -Wall -g q1.c -o q1 alshamlan@alshamlan-VGN-CR520E:/tmp/interview$ ./q1 Segmentation fault (core dumped) alshamlan@alshamlan-VGN-CR520E:/tmp/interview$ gedit q1.c Can someone explain what's going on? thanks.

    Read the article

  • question/problem regarding assigning an array of char *

    - by Fantastic Fourier
    Hi I'm working with C and I have a question about assigning pointers. struct foo { int _bar; char * _car[MAXINT]; // this is meant to be an array of char * so that it can hold pointers to names of cars } int foofunc (void * arg) { int bar; char * car[MAXINT]; struct foo thing = (struct foo *) arg; bar = arg->_bar; // this works fine car = arg->_car; // this gives compiler errors of incompatible types in assignment } car and _car have same declaration so why am I getting an error about incompatible types? My guess is that it has something to do with them being pointers (because they are pointers to arrays of char *, right?) but I don't see why that is a problem. when i declared char * car; instead of char * car[MAXINT]; it compiles fine. but I don't see how that would be useful to me later when I need to access certain info using index, it would be very annoying to access that info later. in fact, I'm not even sure if I am going about the right way, maybe there is a better way to store a bunch of strings instead of using array of char *?

    Read the article

  • c incompatible types in assignment, problem with pointers?

    - by Fantastic Fourier
    Hi I'm working with C and I have a question about assigning pointers. struct foo { int _bar; char * _car[MAXINT]; // this is meant to be an array of char * so that it can hold pointers to names of cars } int foofunc (void * arg) { int bar; char * car[MAXINT]; struct foo thing = (struct foo *) arg; bar = arg->_bar; // this works fine car = arg->_car; // this gives compiler errors of incompatible types in assignment } car and _car have same declaration so why am I getting an error about incompatible types? My guess is that it has something to do with them being pointers (because they are pointers to arrays of char *, right?) but I don't see why that is a problem. when i declared char * car; instead of char * car[MAXINT]; it compiles fine. but I don't see how that would be useful to me later when I need to access certain info using index, it would be very annoying to access that info later. in fact, I'm not even sure if I am going about the right way, maybe there is a better way to store a bunch of strings instead of using array of char *?

    Read the article

  • Why does the output look like this?

    - by cjk
    I have a c program below, I would like to send out a 32 bit message in a particular order Eg.0x00000001. #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <stdint.h> struct test { uint16_t a; uint16_t b; }; int main(int argc, char const *argv[]) { char buf[4]; struct test* ptr=(struct test*)buf; ptr->a=0x0000; ptr->b=0x0001; printf("%x %x\n",buf[0],buf[1]); //output is 0 0 printf("%x %x\n",buf[2],buf[3]); //output is 1 0 return 0; } Then I test it by print out the values in char array. I got output in the above comments. Shouldn't the output be 0 0 and 0 1? since but[3] is the last byte? Is there anything I missed? Thanks!

    Read the article

  • What is wrong with this append func in C

    - by LuckySlevin
    My Struct Definitions. typedef struct inner_list {char word[100]; inner_list*next;} inner_list; typedef struct outer_list { char word [100]; inner_list * head; outer_list * next; } outer_list; And The problem part: void append(outer_list **q,char num[100],inner_list *p) { outer_list *temp,*r; temp = *q; char *str; if(*q==NULL) { temp = (outer_list *)malloc(sizeof(outer_list)); strcpy(temp->word,num); temp->head = p; temp->next=NULL; *q=temp; } else { temp = *q; while(temp->next !=NULL) { temp=temp->next; } r = (outer_list *)malloc(sizeof(outer_list)); strcpy(r->word,num); temp->head = p; r->next=NULL; temp->next=r; } } I don't know what is i'm doing wrong in this append function i'm sending a char array and a linked list to be stored another linked list. But i can't store the linked list in another linked list. I couldn't figure out the problem. Any ideas?

    Read the article

  • Problem Initializing an Array Of Structs

    - by FallSe7en
    I am trying to initialize the following array of the following struct, but my code isn't compiling. Can anybody help me out? The struct/array: struct DiningCarSeat { int status; int order; int waiterNum; Lock customerLock; Condition customer; DiningCarSeat(seatNum) { char* tempLockName; sprintf(tempLockName, "diningCarSeatLock%d", seatNum); char* tempConditionName; sprintf(tempConditionName, "diningCarSeatCondition%d", seatNum); status = 0; order = 0; waiterNum = -1; customerLock = new Lock(tempLockName); customer = new Condition(tempConditionName); } } diningCarSeat[DINING_CAR_CAPACITY]; The relevant errors: ../threads/threadtest.cc: In constructor `DiningCarSeat::DiningCarSeat(int)': ../threads/threadtest.cc:58: error: no matching function for call to `Lock::Lock()' ../threads/synch.h:66: note: candidates are: Lock::Lock(const Lock&) ../threads/synch.h:68: note: Lock::Lock(char*) ../threads/threadtest.cc:58: error: no matching function for call to `Condition::Condition()' ../threads/synch.h:119: note: candidates are: Condition::Condition(const Condition&) ../threads/synch.h:121: note: Condition::Condition(char*) ../threads/threadtest.cc:63: error: expected primary-expression before '.' token ../threads/threadtest.cc:64: error: expected primary-expression before '.' token ../threads/threadtest.cc: At global scope: ../threads/threadtest.cc:69: error: no matching function for call to `DiningCarSeat::DiningCarSeat()' ../threads/threadtest.cc:51: note: candidates are: DiningCarSeat::DiningCarSeat(const DiningCarSeat&) ../threads/threadtest.cc:58: note: DiningCarSeat::DiningCarSeat(int) Thanks in advance!

    Read the article

  • C# struct and NuSOAP(php)

    - by opx
    Hello Im trying to build a client in c# that talks with some remote (php)server with SOAP using the NuSOAP library. Here im using a struct/object that will containt the user info of some user: public struct UserProfile { public string username; public string password; public string email; public string site; public string signature; public int age; public int points; And this is the PHP Code: server->wsdl->addComplexType( 'UserProfile', 'complexType', 'struct', 'all', '', array( 'username' => array('name' => 'username', 'type' => 'xsd:string'), 'password' => array('name' => 'password', 'type' => 'xsd:string'), 'email' => array('name' => 'email', 'type' => 'xsd:string'), 'site' => array('name' => 'site', 'type' => 'xsd:string'), 'signature' => array('name' => 'signature', 'type' => 'xsd:string'), 'age' => array('name' => 'age', 'type' => 'xsd:int'), 'points' => array('name' => 'username', 'type' => 'xsd:int'), ) ); $server->wsdl->addComplexType( 'UserProfileArray', 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:UserProfile[]')), 'tns:UserProfile' ); $server->register("getUserProfile", array(), array('return' => 'tns:UserProfileArray'), $namespace, false, 'rpc', false, 'Get the user profile object' ); function getUserProfile(){ $profile['username'] = "user"; $profile['password'] = "pass"; $profile['email'] = "usern@ame"; $profile['site'] = "u.com"; $profile['signature'] = "usucsdckme"; $profile['age'] = 111; $profile['points'] = time() / 2444; return $profile; } Now I already have a working login function, and I want to get the info about the logged in user but I dont know howto obtain these. This is what im using to get the userinfo: string user = txtUser.Text; string pass = txtPass.Text; SimpleService.SimpleService service = new SimpleService.SimpleService(); if(service.login(user, pass)){ //logged in } SoapApp.SimpleService.UserProfile[] user = service.getUserProfile(); // THIS LINE GIVES ME AN EXCEPTION MessageBox.Show(user[0].username + "--" + user[0].points); The getUserProfile() function produces an error: System.Web.Services.Protocols.SoapException was unhandled Message="unable to serialize result" Source="System.Web.Services" or I get something like 'cant parse xml' error. The article I used for this was from: http://www.sanity-free.org/125/php_webservices_and_csharp_dotnet_soap_clients.html The difference on what they are doing and what I try to do is that I only want to get one object returned instead of multiple 'MySoapObjects'. I hope someone is familiar with this and could help me, thanks in advance! Regards, opx

    Read the article

  • Boost class/struct serialization to byte array

    - by Dave18
    does boost library provide functions to pack the class/struct data into a byte array to shorten the length of serialized data? Currently i'm using stringstream to get the serialized data, for example - struct data { std::string s1; std::string s2; int i; }; template <typename Archive> void serialize(Archive &ar, data &d, const unsigned int version) { ar & d.s1; ar & d.s2; ar & d.i; } int main() { data d; d.s1 = "This is my first string"; d.s2 = "This is my second string"; d.i = 10000; std::stringstream archive_stream; boost::archive::text_oarchive archive(archive_stream); archive.operator <<(d); } How would i use a byte array instead of stringstream for data?

    Read the article

  • struct and rand()

    - by teoz
    I have a struct with an array of 100 int (b) and a variable of type int (a) I have a function that checks if the value of "a" is in the array and i have generated the array elements and the variable with random values. but it doesn't work can someone help me fix it? #include <stdio.h> #include <stdlib.h> #include <time.h> typedef struct { int a; int b[100]; } h; int func(h v){ int i; for (i=0;i<100;i++){ if(v.b[i]==v.a) return 1; else return 0; } } int main(int argc, char** argv) { h str; srand(time(0)); int i; for(i=0;0<100;i++){ str.b[i]=(rand() % 10) + 1; } str.a=(rand() % 10) + 1; str.a=1; printf("%d\n",func(str)); return 0; }

    Read the article

  • How to store a linked list in a struct in C

    - by LuckySlevin
    typedef struct child_list {int count; char vo[100]; child_list*next;} child_list; typedef struct parent_list { char vo[100]; child_list * head; int count; parent_list * next; } parent_list; As you can see there are two structures. child_list is used to create a linked list. And this list will be stored in a linked list of parent list. My problem is to display the child list which in the parent_list. My desire to get while displaying the linked list of parent_list: This lists work with this logic. I already made append and other stuff. For example if i enter ab cd ab ja cd ab Word Count List ab 3 cd->ja cd 2 ab->ab ja 1 cd The problematic part is displaying child_list which is in the parent_list nodes(List column of output). I don't know my question is clear please ask for further info.

    Read the article

  • overloading "<<" with a struct (no class) cout style

    - by monkeyking
    I have a struct that I'd like to output using either 'std::cout' or some other output stream. Is this possible without using classes? Thanks #include <iostream> #include <fstream> template <typename T> struct point{ T x; T y; }; template <typename T> std::ostream& dump(std::ostream &o,point<T> p) const{ o<<"x: " << p.x <<"\ty: " << p.y <<std::endl; } template<typename T> std::ostream& operator << (std::ostream &o,const point<T> &a){ return dump(o,a); } int main(){ point<double> p; p.x=0.1; p.y=0.3; dump(std::cout,p); std::cout << p ;//how? return 0; } I tried different syntax' but I cant seem to make it work.

    Read the article

  • Function returning pointer to struct

    - by GammaGuy
    I am having some issues with code that is returning a pointer to a struct declared inside a class. Here is my code so far: SortedList.h #ifndef SORTEDLIST_H #define SORTEDLIST_H class SortedList{ public: SortedList(); ... private: struct Listnode { Student *student; Listnode *next; }; static Listnode *copyList (Listnode *L); }; #endif SortedList.cpp #include "SortedList.h" ... // Here is where the problem lies Listnode SortedList::*copyList(Listnode *L) { return 0; // for NULL } Apparently, the copy list method wont compile. I am using Microsoft Visual Studio and the compiler tells me that "Listnode" is unidentified. When I try to compile, here is whhat I get: 1>------ Build started: Project: Program3, Configuration: Debug Win32 ------ 1> SortedList.cpp 1>c:\users\owner\documents\college\fall 2012\cs 368 - learn c++\program3\program3\sortedlist.cpp(159): error C2657: 'SortedList::*' found at the start of a statement (did you forget to specify a type?) 1>c:\users\owner\documents\college\fall 2012\cs 368 - learn c++\program3\program3\sortedlist.cpp(159): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\owner\documents\college\fall 2012\cs 368 - learn c++\program3\program3\sortedlist.cpp(159): error C2065: 'L' : undeclared identifier 1>c:\users\owner\documents\college\fall 2012\cs 368 - learn c++\program3\program3\sortedlist.cpp(159): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\owner\documents\college\fall 2012\cs 368 - learn c++\program3\program3\sortedlist.cpp(159): fatal error C1903: unable to recover from previous error(s); stopping compilation ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== Help would be greatly appreciated...ASAP

    Read the article

  • Core-audio - constructing an AudioBufferList

    - by mustISignUp
    The definition of AudioBufferList looks weird to me… i guess my C is not so good struct AudioBufferList { UInt32 mNumberBuffers; AudioBuffer mBuffers[kVariableLengthArray]; }; typedef struct AudioBufferList AudioBufferList; Why AudioBuffer mBuffers[kVariableLengthArray]; and not AudioBuffer *mBuffers; ? kVariableLengthArray appears to be == 1. Eh? I think i have it working but would appreciate it if anyone could set me straight.

    Read the article

  • Imitate database in C

    - by Mohit Deshpande
    I am fairly new to C. (I have good knowledge of C# [Visual Studio] and Java [Eclipse]) I want to make a program that stores information. My first instinct was to use a database like SQL Server. But I don't think that it is compatible with C. So now I have two options: Create a struct (also typedef) containing the data types. Find a way to integrate SQLite through a C header file Which option do you think is best? Or do you have another option? I am kind of leaning toward making a struct with a typedef, but could be pursuaded to change my mind.

    Read the article

  • Structs, strtok, segmentation fault

    - by FILIaS
    I'm trying to make a programme with structs and files.The following is just a part of my code(it;s not all). What i'm trying to do is: ask the user to write his command. eg. delete John eg. enter John James 5000 ipad purchase. The problem is that I want to split the command in order to save its 'args' for a struct element. That's why i used strtok. BUT I'm facing another problem in who to 'put' these on the struct. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 100 char command[1500]; struct catalogue { char short_name[50]; char surname[50]; signed int amount; char description[1000]; }*catalog[MAX]; int main ( int argc, char *argv[] ) { int i,n; char choice[3]; printf(">sort1: Print savings sorted by surname\n"); printf(">sort2: Print savings sorted by amount\n"); printf(">search+name:Print savings of each name searched\n"); printf(">delete+full_name+amount: Erase saving\n"); printf(">enter+full_name+amount+description: Enter saving \n"); printf(">quit: Update + EXIT program.\n"); printf("Choose your selection:\n>"); gets(command); //it save the whole command /*in choice it;s saved only the first 2 letters(needed for menu choice again)*/ strncpy(choice,command,2); choice[2]='\0'; char** args = (char**)malloc(strlen(command)*sizeof(char*)); memset(args, 0, sizeof(char*)*strlen(command)); char* curToken = strtok(command, " \t"); for (n = 0; curToken != NULL; ++n) { args[n] = strdup(curToken); curToken = strtok(NULL, " \t"); *catalog[n]->short_name=*args[1]; *catalog[n]->surname=args[2]; catalog[n]->amount=atoi(args[3]); *catalog[n]->description=args[4]; } return 0; } I get a warning (warning: assignment makes integer from pointer without a cast) for the lines: *catalog[n]->short_name=*args[1]; *catalog[n]->surname=args[2]; *catalog[n]->description=args[4]; As a result, after running the program i get a Segmentation Fault... Any help? Any ideas?

    Read the article

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