struct

Using structs of derived class y base template

拥有回忆 提交于 2019-12-24 07:46:10
问题 I have a base template: template <typename T> class Base { public: void method(T); }; And a derived class: class Derived: public Base<Derived::status_t> { public: typedef struct { uint8_t value; } status_t; } I'm have more derived classes, each one with it status_t specific struct. I want to use these structs in the base class, but the compiler give me an error: Error[Pe070]: incomplete type is not allowed. I suppose that the problem is that the struct is not defined in the moment that the

Adding two members of a struct together

为君一笑 提交于 2019-12-24 07:35:56
问题 typedef struct Int40 { // a dynamically allocated array to hold a 40 // digit integer, stored in reverse order int *digits; } Int40; in main I have these functions implemented, and loadCryptoVariable and loadHwConfigVariable each return a 40 digit value Int40 *p; Int40 *q; Int40 *r; p = loadCryptoVariable("cryptoVarFile"); q = loadHWConfigVariable(0); r = kw26Add( p, q); However, I can't figure out how to add the two together..(side note: I am aware I shouldn't malloc like that and use a more

passing struct pointer to functions not working

醉酒当歌 提交于 2019-12-24 07:15:11
问题 Motive: Passing struct to functions such as we can change it in any function and retrieve any value in any function. I picked up this code from: http://cboard.cprogramming.com/c-programming/126381-passing-structure-reference-through-4-functions.html#post942397 I tweaked it a little and here it is: struct_passing.h typedef struct thing { char *x; }thing_t; struct_passing.c #include <stdio.h> #include "struct_passing.h" void f4(thing_t *bob) { bob->x = "changed"; } void f3(thing_t *bob) { f4

Writing a linked list to binary file(C)

余生长醉 提交于 2019-12-24 07:12:54
问题 So I have set up a linked list and read data from a file, done some calculation and manipulation and now I want to store the new list into a binary file. Here is my struct setup: typedef struct Comp{ char name[5]; char node1[5], node2[5]; float value; //value }ComponentType; typedef struct ListNodeT{ ComponentType Component; float voltage, power, current; struct ListNodeT *nextPtr; }ListNodeType; In a separate function I am trying to write to a a file: FILE *filePtr; char fileName[13] =

One method to handle all the struct types that embed one common struct (json marshalling)

我们两清 提交于 2019-12-24 06:47:13
问题 I have a gin-gonic web app with somewhat MVC architecture. I created a couple of models, all of them embed one common struct: type User struct { ID int Name string } type Admin struct { User Level int } ... { User } Now I want to store them in database in json format. The goal I want to accomplish is to code only one function/method that will marshal any model and will save save it into DB. This method must marshal all the fields of current model, not only from User struct, e.g. User must be

Is this the right way for a block inside a struct to access a member variable in the same struct?

柔情痞子 提交于 2019-12-24 06:45:02
问题 I'm experimenting with Obj-C blocks and trying to have a struct with two blocks in it where one block is to change what the other block does. this is a really roundabout way to do something simple... and there may be better ways to do it, but the point of the exercise is for me to understand blocks. here's the code , it doesn't work, so what am I missing/not understanding and/or doing wrong? //enumerate my math operation options so i can have something more understandable //than 0, 1, 2, etc.

How to create Python ctypes structures for MS Windows PACKAGE_ID and PACKAGE_INFO structures?

孤人 提交于 2019-12-24 06:37:20
问题 I'm trying to translate this SO answer code into Python (and a bit from the other answer there) with the help of official documentation for PACKAGE_ID and PACKAGE_INFO. I'm getting full package names by GetPackageFullName , but some of my structures aren't formed well as OpenPackageInfoByFullName gives Unicode characters that are jibberish to me. Also PackageIdFromFullName returns ERROR_INSUFFICIENT_BUFFER when called. EDIT : As Paul Cornelius noticed, my code had issues with PACKAGE_INFO

Are arrays in structs freed on deletion?

六眼飞鱼酱① 提交于 2019-12-24 05:57:00
问题 If I were to use something like this in C++, struct socket_t { sockaddr_in address; char buffer[2048]; int FD; } socket_t *clients[256]; memset(clients, 0, 256); and then create objects in it, socket_t **free = (socket_t**) memchr(clients, 0, 256); *free = new socket_t; and then use delete on some of the elements, delete clients[index]; would all members be safely freed (especially the buffer)? I don't want to waste 2 KiB on each item I create. I'm asking this because I noticed sizeof returns

How to check if a char contains a specific letter

人走茶凉 提交于 2019-12-24 05:56:37
问题 I'm trying to produce code that will check how many "A", "C", "G", and "T" characters a char contains. But I'm a little unsure how to go about doing this.. because as far as I know there aren't any operators like .contains() to check with. The desired output would be something like: "The char contains (variable amount) of letter A's" In my code I have this right now: DNAnt countDNAnt(char strand) { DNAnt DNA; if (isupper(strand) == "A") { DNA.adenine++; } else if (isupper(strand) == "C") {

C: how would I write a search function to look for a match in a struct array, and return (print) the entire struct it matched?

£可爱£侵袭症+ 提交于 2019-12-24 05:51:12
问题 #include <stdio.h> #include <stdlib.h> #include <string.h> #define RECORDS 10 The function below is what I am asking for help with. static char searchforRecordbystate(char input[3]) { for / while /if loop search struct array members if a match is found return (print) the entire struct where a match was found return 0; } Main function - first time ever using pointers, (xcode is not complaining with it set to be as strict as possible) but all of you are welcome to complain, especially if I am