struct

Struct is empty after Json unmarshal when accessed by another package

佐手、 提交于 2021-01-28 14:20:44
问题 I'm am using a struct Contact that has a Load() method. The idea is that Load() populates Contact 's fields with data. The data is unmarshalled from json returned by a server. Once loaded, I want to be able to access the data on Contact . I know that the json is unmarshalling correctly because I can print the data to the console within Load() , immediately after it has been unmarshalled. However, this data is not present on Contact once it has been loaded. So when I create a new Contact and

C struct Inheritance vs C++ POD struct Inheritance

ⅰ亾dé卋堺 提交于 2021-01-28 12:30:41
问题 Suppose I use the fairly common idiom to define struct inheritance in my_header.h : struct A { int a_field; ... }; struct B { struct A _as_A; int b_field; ... }; Now in my C code I can do binstance._as_A.a_field , or I can cast a pointer to B to a pointer to A, and so forth. My question is this. Suppose that I now define a new C++ header my_header.hpp : struct A { int a_field; ... } struct B : A { int b_field; ... } Suppose I do this taking care to make sure B is a POD type . Am I guaranteed

Overloading with struct in C

匆匆过客 提交于 2021-01-28 12:21:44
问题 I am trying to write a function with the same name, but that accepts 3 different typers of structs.I don't know how I can write the parameters to do this.So in the _______, there should be proffesore, amminustratore, studente. Sp that the function can accept all 3 types of struct but only one at the time. Here is the code: int confermaCredenziali(struct ______ dati, char *uN, char *pW); struct amministratore{ char userName[MAX_LNG]; char passWord[MAX_LNG]; int stato; struct ammin *next; };

Possible to initialize/assign a struct pointer?

自作多情 提交于 2021-01-28 11:53:50
问题 Let's say I have the following struct and two versions to initialize it: #include <stdio.h> typedef struct Car *CarPtr; typedef struct Car { const char* name; unsigned int price; } Car; int main(void) { Car ford = { .name = "Ford F-150", .price = 25000 }; print_struct(&ford); // is this possible to do in a single assignment? CarPtr jeep = { .name = "Jeep", .price = 40000 }; print_struct(jeep); } Is the second version possible to do directly? Or do I need to do something along the lines of:

sigaction : using “void (*sa_sigaction)(int, siginfo_t *, void *);”

筅森魡賤 提交于 2021-01-28 10:01:18
问题 In sigaction manpage it's written : sa_sigaction also specifies the action to be associated with signum . This function receives the signal number as its first argument, a pointer to a siginfo_t as its second argument and a pointer to a ucon- text_t (cast to void* ) as its third argument. So we can pass arguments to the signal handler (throught void* ), but I can't find the way. Is there no way to put it anywhere? Example : struct ping_val { int data1; int data2; }; void ping(int sig, siginfo

initialize std::array <struct, size>

拜拜、爱过 提交于 2021-01-28 09:11:08
问题 I am trying to defined and initialize an array of struct. #include <iostream> #include <array> int main() { struct row{ double a0; double a1; }; //method 0: this way works row c[2] ={{1.0,2.0},{3.0,4.0}}; //method 1: declare and initialization in same line //std::array<row, 2> a = { {1.0, 2.0}, {3.0, 4.0} };//error: Excess elements in struct initializer std::array<row, 2> a = {{ {1.0, 2.0}, {3.0, 4.0} }}; //double brace //method 2, declare, then initialize in different line std::array<row, 2>

Get a struct based on member values

吃可爱长大的小学妹 提交于 2021-01-28 07:21:00
问题 I have a huge struct array and I created different function to get the struct pointer based on a member's value: typedef struct { uint32_t a; uint32_t b; uint32_t c; uint32_t d; } test_t; test_t test[10]; // Initialized somewhere else static test_t* __get_struct_by_a(uint_32_t a) { for (uint32_t i = 0; i < 10; i++) { if (test[i].a == a) return &test[i]; } return NULL; } static test_t* __get_struct_by_b(uint_32_t b) { ... } Is there an easy way to tackle this in C instead of create a lookup

Define a struct with a member pointing to another member

吃可爱长大的小学妹 提交于 2021-01-28 07:02:10
问题 I'm trying to program a network in C. I have nodes which are linked to each other and I 'd like to do that by making the struct member point to another member (not to another node, because I want to preserve the identity of the links). The code I made to do that is something like: struct node{ int k; //number of links struct node.link **link; //<- wrong }; but this is not right as node is not a variable but a type of variable (this is already discussed as an error in another QA: first you

How to save a struct property of a user control in Windows Forms Designer?

给你一囗甜甜゛ 提交于 2021-01-28 04:41:06
问题 I've checked the answers of this question: Modifying structure property in a PropertyGrid And also SizeConverter from .net. But not helpful, my property is still not saved. I have a struct, a user control, and a custom type converter. public partial class UserControl1 : UserControl { public Bar bar { get; set; } = new Bar(); } [TypeConverter(typeof(BarConverter))] public struct Bar { public string Text { get; set; } } public class BarConverter : ExpandableObjectConverter { public override

How exactly does constexpr double Point::* coords[3] work? [duplicate]

ⅰ亾dé卋堺 提交于 2021-01-28 04:03:10
问题 This question already has answers here : Pointer to class data member “::*” (15 answers) Closed 6 months ago . So I've been looking at some stuff and found this thread Aliasing struct and array the C++ way And this is the answer to the question #include <math.h> struct Point { double x; double y; double z; }; double dist(struct Point *p1, struct Point *p2) { constexpr double Point::* coords[3] = {&Point::x, &Point::y, &Point::z}; double d2 = 0; for (int i=0; i<3; i++) { double d = p1->*coords