structure

pointer to structure and self pointers

♀尐吖头ヾ 提交于 2019-12-11 06:28:52
问题 What is the difference between self referential pointer in structure and pointer to structure? struct abc { int data; struct abc *next; } struct abc *pt; What are the differences between *next and *pt ?? How they differ in their use?? I am really in doubt between these two I am a beginner First example is used mainly for linked list Are pointer to structure node and self referential pointer the same thing? please see see-programming.blogspot.in/2013/05/chain-hashing-separate-chaining-with

C++ dynamic memory allocation with arrays in a structure

此生再无相见时 提交于 2019-12-11 06:06:13
问题 There have been similar questions to this but they are all in C, rather than C++, so I have asked a new question. I have been following a C++ tutorial and after completing the dynamic memory, pointers and structure sections I tried to put them together in an example program. Essentially, I am trying to have a dynamically allocated array of a structure (the program inputs "produce" :P and displays the result). The compiler errors: 'base operand of '->' has non-pointer type 'produce' for the

errors while trying to pass a structure to a function

蓝咒 提交于 2019-12-11 05:52:25
问题 In the following program I try to pass a structure to a function. But I get errors,and I do not understand why. What mistake have I made in this program ? I am using gcc for compiling this c program. #include <stdio.h> struct tester { int x; int *ptr; }; void function(tester t); int main() { tester t; t.x = 10; t.ptr = & t.x; function(t); } void function(tester t) { printf("%d\n%p\n",t.x,t.ptr); } Errors : gcc tester.c -o tester tester.c:8:15: error: unknown type name ‘tester’ tester.c: In

C - Unable to free memory allocated within a linked list structure

坚强是说给别人听的谎言 提交于 2019-12-11 04:48:31
问题 Consider the following code snippet struct node { char *name; int m1; struct node *next; }; struct node* head = 0; //start with NULL list void addRecord(const char *pName, int ms1) { struct node* newNode = (struct node*) malloc(sizeof(struct node)); // allocate node int nameLength = tStrlen(pName); newNode->name = (char *) malloc(nameLength); tStrcpy(newNode->name, pName); newNode->m1 = ms1; newNode->next = head; // link the old list off the new node head = newNode; } void clear(void) {

Structuring classes with multiple inheritance

亡梦爱人 提交于 2019-12-11 04:24:00
问题 This isn't an actual programming question, I just need advice on how to structure a part of my program. The program is divided into a client and a server part. Both share certain code, including base classes. Here's a representation of the code I'm having trouble with: Shared classes: class BaseEntity { public: virtual void EmitSound(std::string snd) {} virtual bool IsPlayer() {return false;} }; class BasePlayer : public BaseEntity { public: bool IsPlayer() {return true;} } Serverside classes

Go - get parent struct

怎甘沉沦 提交于 2019-12-11 03:03:56
问题 I'd like to know how to retrieve the parent struct of an instance. I have no idea how to implement this. For instance: type Hood struct { name string houses []House } type House struct { name string people int16 } func (h *Hood) addHouse(house House) []House { h.houses = append(h.houses, house) return h.houses } func (house *House) GetHood() Hood { //Get hood where the house is situated return ...? } Cheers 回答1: You should retain a pointer to the hood. type House struct { hood *Hood name

structure array giving wrong output on sorting

柔情痞子 提交于 2019-12-11 02:52:04
问题 1)I have a structure struct node { char symbol; int freq; int left, right,root; int value; short is_sorted; }; struct node data[1000]; where data[215].freq (frequency) {0,1,2,3,4,5} is obtained by reading following alphabetical symbols(symbol) (abcdef) values from a file "Input.txt" as a sole argument.Now i have to add two minimum frequencies of this array and then position the newly element obtained in the same array such that it will maintain the increasing order of the freq(It was already

Is `struct` keyword needed in declaring a variable of structure?

旧巷老猫 提交于 2019-12-11 02:28:01
问题 I have come to know from book that for declaring a structure variable it is necessary a preceding struct keyword, but without that preceding struct in my Bloodshed\DevC++ compiler variable can be declared without any error like following, struct stype { int ival; float fval; double dval; }; and in main, stype s; s.ival=10;s.dval=23.23;s.fval=233.23; printf("%d %f %lf\n",s.ival,s.fval,s.dval); This correctly prints what should be printed. Is there any modification behind using this struct

mysql select data from two tables and different structure

寵の児 提交于 2019-12-11 02:21:47
问题 Hi there i'm building up a kind of agenda/website with php/mysql. This agenda has public events and users' personal notes ordered by date. I need to load all the events from EVENTS TABLE in database and the notes from NOTES TABLE. But those two tables have a completely different structure and they just have one same field: DATETIME. How can i sort by date public events and personal notes then? Please help me out! =) thanks luca 回答1: Improving Don's answer per OP comments, you can add a column

ideal thread structure question (involves multiple thread communication)

安稳与你 提交于 2019-12-11 02:20:30
问题 I'm writing an application that listens for sound events (using messages passed in with Open Sound Control), and then based on those events pauses or resumes program execution. My structure works most of the time but always bombs out in the main loop, so I'm guessing it's a thread issue. Here's a generic, simplified version of what I'm talking about: import time, threading class Loop(): aborted = False def __init__(self): message = threading.Thread(target=self.message, args=((0),)) message