Search Results

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

Page 6/103 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • how to refer to the current struct in an overloaded operator?

    - by genesys
    Hi! I have a struct for which i want to define a relative order by defining < , , <= and = operators. actually in my order there won't be any equality, so if one struct is not smaller than another, it's automatically larger. I defined the first operator like this: struct MyStruct{ ... ... bool operator < (const MyStruct &b) const {return (somefancycomputation);} }; now i'd like to define the other operators based on this operator, such that <= will return the same as < and the other two will simply return the oposite. so for example for the operator i'd like to write something like bool operator > (const MyStruct &b) const {return !(self<b);} but i don't know how to refere to this 'self' since i can refere only to the fields inside the current struct. whole is in C++ hope my question was understandable :) thank you for the help!

    Read the article

  • float** allocation limit + serialized struct problem. Need advice!

    - by jmgunn
    basically im getting an allocation limit error/warning when i create a float** array. the function i am calling to fill the float** retrieves data from a struct loaded from a file. The function works fine when i use one object but when i load 2 objects into memory i get the limit error. I am pretty sure this is to do with byte alignment or a similar thing because my struct is saved with a float** member which i am sure you are not susposed to do !?! Please confirm this! The next question i have now is how to save/serialize the float** member of this struct? I cant really afford to put an upper bound on the array ie "float [10000][3]" because i need/want to use this structure as a base for many other types of objects that may have well under the upper bound. Stroking my chin here! Any help/advice will recieve my highest gratitude. BTW these said struct objects will be used in a game/graphics package, the float** is a float[3] array for storing vertices in a model. Much thanks in advance

    Read the article

  • How do i change the address of a New struct in a loop?!

    - by Yasin
    Hi guys, i'm writing a simple code which is about polynomials using link lists in C#. the problem i have is that whenever it creates a new struct (node) in the for loop it gives it the same address as the previous node was given. so how do i fix it ? here is my struct : struct poly { public int coef; public int pow; public poly* link;} ; and here is the where the problem occurs: for (; i < this.textBox1.Text.Length; i++) { q = new poly(); ...... p->link = &q; } &q remains unchanged !

    Read the article

  • How to determine if a .NET Type is a custom struct?

    - by SztupY
    Hi! How to write a simple method, that checks whether a concrete type is a custom struct (created with public struct { };) or not. Checking Type.IsValueType is not enough, because it is also true to int, long, etc, and adding a check to !IsPrimitiveType won't exclude decimal, DateTime and maybe some other value types. I know that most of the built in value types are actually "structs", but I only want to check for "custom structs" These questions are mostly the same but without the answer I need: #1 #2 #3

    Read the article

  • C# replacing out parameters with struct

    - by Jonathan
    I'm encountering a lot of methods in my project that have a bunch of out parameters embedded in them and its making it cumbersome to call the methods as I have to start declaring the variables before calling the methods. As such, I would like to refactor the code to return a struct instead and was wondering if this is a good idea. One of the examples from an interface: void CalculateFinancialReturnTotals(FinancialReturn fr, out decimal expenses, out decimal revenue, out decimal levyA, out decimal levyB, out decimal profit, out decimal turnover, out string message) and if I was to refactor that, i would be putting all the out parameters in the struct such that the method signature is much simpler as below. [structName] CalculateFinancialReturnTotals(FinancialReturn fr); Please advise.

    Read the article

  • Why do I get "request for member in something not a struct or union" from this code?

    - by pyroxene
    I'm trying to teach myself C by coding up a linked list. I'm new to pointers and memory management and I'm getting a bit confused. I have this code: /* Remove a node from the list and rejiggle the pointers */ void rm_node(struct node **listP, int index) { struct node *prev; struct node *n = *listP; if (index == 0) { *listP = *listP->next; free(n); return; } for (index; index > 0; index--) { n = n->next; if (index == 2) { prev = n; } } prev->next = n->next; free(n); } to remove an element from the list. If I want to remove the first node, I still need some way of referring to the list, which is why the listP arg is a double pointer, so it can point to the first element of the list and allow me to free the node that used to be the head. However, when I try to dereference listP to access the pointer to the next node, the compiler tells me error: request for member ‘next’ in something not a structure or union . What am I doing wrong here? I think I might be hopelessly mixed up..?

    Read the article

  • error: invalid type argument of '->' (have 'struct node')

    - by Roshan S.A
    Why cant i access the pointer "Cells" like an array ? i have allocated the appropriate memory why wont it act like an array here? it works like an array for a pointer of basic data types. #include<stdio.h> #include<stdlib.h> #include<ctype.h> #define MAX 10 struct node { int e; struct node *next; }; typedef struct node *List; typedef struct node *Position; struct Hashtable { int Tablesize; List Cells; }; typedef struct Hashtable *HashT; HashT Initialize(int SIZE,HashT H) { int i; H=(HashT)malloc(sizeof(struct Hashtable)); if(H!=NULL) { H->Tablesize=SIZE; printf("\n\t%d",H->Tablesize); H->Cells=(List)malloc(sizeof(struct node)* H->Tablesize); should it not act like an array from here on? if(H->Cells!=NULL) { for(i=0;i<H->Tablesize;i++) the following lines are the ones that throw the error { H->Cells[i]->next=NULL; H->Cells[i]->e=i; printf("\n %d",H->Cells[i]->e); } } } else printf("\nError!Out of Space"); } int main() { HashT H; H=Initialize(10,H); return 0; } The error I get is as in the title-error: invalid type argument of '->' (have 'struct node').

    Read the article

  • C#. Struct design. Why 16 byte is recommended size?

    - by maxima120
    I read Cwalina book (recommendations on development and design of .NET apps). He says that good designed struct has to be less than 16 bytes in size (for performance purpose). My questions is - why exactly is this? And (more important) can I have larger struct with same efficiency if I run my .NET 3.5 (soon to be .NET 4.0) 64-bit application on i7 under Win7 x64 (is this limitation CPU / OS based)? Just to stress again - I need as efficient struct as it is possible. I try to keep it in stack all the time, the application is heavily multi-threaded and runs on sub-millisecond intervals, the current size of the struct is 64 byte.

    Read the article

  • Is there a practical alternative to struct inheritance? (C#)

    - by Tim Coulter
    I am writing code that will populate the Margin, Padding and BorderThickness properties of classes in the System.Windows.Documents namespace. Each of these properties accepts a value in the form of a System.Windows.Thickness, which is a struct. However, I wish to associate some additional data with each of these property assignments, which may subsequently be retrieved by my code. If Thickness were a class, I would inherit from it and define properties in the subclass to store my additional data items. But since it is a struct, inheritance is not possible. Is there any practical way to achieve this, while maintaining type-compatibility with the properties I am populating? Thanks for your ideas, Tim

    Read the article

  • Apache thrift, struct contain itself

    - by mamu
    I am looking into thrift for serialization of data. But Document says cyclic structs - Structs can only contain structs that have been declared before it. A struct also cannot contain itself One of our requirement is Struct A List of Child items Items(Items are Struct A ) So reading requirement i can't have Struct within itself at any level? can i have it in cyclic model as i have it above. Struct is not member of Struct directly but it has some other member and it contains struct. Their document is not so well descriptive. Is it possible in Thrift? Does protobuf supports it?

    Read the article

  • Is it a good practice to pass struct object as parameter to a function in c++?

    - by tsubasa
    I tried an example live below: typedef struct point { int x; int y; } point; void cp(point p) { cout<<p.x<<endl; cout<<p.y<<endl; } int main() { point p1; p1.x=1; p1.y=2; cp(p1); } The result thats printed out is: 1 2 which is what I expected. My question is: Does parameter p get the full copy of object p1? If so, I wonder if this is a good practice? (I assumed when the struct gets big in size, this will create a lot of copy overhead).

    Read the article

  • Cannot call struct properties from HAML file

    - by Lander
    I have the following code in my controller: @nav_items = ActiveSupport::OrderedHash.new @nav_items[:home] = Struct::NavItem.new("Home", nil, "/", "icon-home") @nav_items[:about] = Struct::NavItem.new("About", nil, "/about", "icon-heart") @nav_items[:contact] = Struct::NavItem.new("Contact", nil, "/contact", "icon-envelope") if (current_user != nil && current_user.admin?) @nav_items[:admin_divider] = Struct::NavItem.new(nil, "divider-vertical", nil, nil) @nav_items[:admin] = Struct::NavItem.new("Admin", nil, "/admin", "") end And the following in my view: - @nav_items.each do |nav_item| %li{ :class => nav_item[:class] } %a{ :href => nav_item[:link] }= nav_item[:text] And my struct definition: Struct.new("NavItem", :text, :class, :link, :icon_class) I'm relatively new to Ruby, Rails, and HAML, but in another project using ERB rendering, code like that worked fine. I've tried referencing properties by doing something like nav_item.link as well, but that still does not work. The error I get with my current code is: Symbol as array index By using code like nav_item.link: undefined method `link' for #< Array:0x126970ff0 As this is my first time using HAML, I'm not too sure what I'm doing wrong.

    Read the article

  • C++ circular dependency - namespace vs struct

    - by Dead or Alive
    Please educate me. Why does this compile: struct compiles { struct A; struct B { B(const A &a) : member(a.member) { } int member; }; struct A { A(const B &b) : member(b.member) { } int member; }; }; while this does not: namespace doesnt { struct A; struct B { B(const A &a) : member(a.member) { } int member; }; struct A { A(const B &b) : member(b.member) { } int member; }; } (in MSVC 9.0)

    Read the article

  • referencing struct fields in c with square brackets and an index instead of . and ->?

    - by lsiebert
    Assuming I have a structure such as: typedef struct { char * string1; char * string2; } TWO_WORDS; such that all the fields are of the same type, and my main has TWO_WORDS tw; can I reference string1 with tw[0] and string2 with two[1]? If so: is this part of the c standard? do i have to cast the struct to an array first? what about fields which are different sizes in memory what about fields which are different types but the same size? can you do pointer arithmetic within a structure? -

    Read the article

  • A queue in C using structs and dynamic memory allocation (linked list)

    - by Martin Pugh
    I am tasked with making a queue data structure in C, as a linked list. Our lecturer gave us a large amount of code to implement a stack, but we have to adapt it to create a queue. The code our lecturer gave us ends up not compiling and segfaulting at the exact same point as the code I wrote for the queue. I'm very new to structs, malloc and C in general, so there could be something painfully obvious I've overlooked. Here is the code I am using: #include <stdio.h> #include <stdlib.h> struct node{ int data; //contains the actual data struct node *prev; //pointer to previous node (Closer to front) struct node *next; //pointer to next node (Closer to back) }; typedef struct node *Nodepointer; struct queue{ Nodepointer front; Nodepointer back; }; typedef struct queue *Queuepointer; main(){ Queuepointer myqueue; //create a queue called myqueue init(myqueue); //initialise the queue Nodepointer new = (Nodepointer)malloc(sizeof(struct node)); myqueue->front = new; } int init(Queuepointer q){ q = (Queuepointer)malloc(sizeof(struct queue)); q->front = NULL; q->back = NULL; } The idea is that the queue struct 'contains' the first and last nodes in a queue, and when a node is created, myqueue is updated. However, I cannot even get to that part (pop and push are written but omitted for brevity). The code is segfaulting at the line myqueue->front = new; with the following gdb output: Program received signal SIGSEGV, Segmentation fault. 0x08048401 in main () at queue.c:27 27 myqueue->front = new; Any idea what I'm doing wrong?

    Read the article

  • How is it legal to reference an undefined type inside a structure?

    - by paxdiablo
    As part of answering another question, I came across a piece of code like this, which gcc compiles without complaint. typedef struct { struct xyz *z; } xyz; int main (void) { return 0; } This is the means I've always used to construct types that point to themselves (e.g., linked lists) but I've always thought you had to name the struct so you could use self-reference. In other words, you couldn't use xyz *z within the structure because the typedef is not yet complete at that point. But this particular sample does not name the structure and it still compiles. I thought originally there was some black magic going on in the compiler that automatically translated the above code because the structure and typedef names were the same. But this little beauty works as well: typedef struct { struct NOTHING_LIKE_xyz *z; } xyz; What am I missing here? This seems a clear violation since there is no struct NOTHING_LIKE_xyz type defined anywhere. When I change it from a pointer to an actual type, I get the expected error: typedef struct { struct NOTHING_LIKE_xyz z; } xyz; qqq.c:2: error: field `z' has incomplete type Also, when I remove the struct, I get an error (parse error before "NOTHING ...). Is this allowed in ISO C?

    Read the article

  • forward declare typedef'd struct

    - by Steve
    I can't figure out how to forward declare a windows struct. The definition is typedef struct _CONTEXT { .... } CONTEXT, *PCONTEXT I really don't want to pull into this header, as it gets included everywhere. I've tried struct CONTEXT and struct _CONTEXT with no luck (redefinition of basic types with the actuall struct in winnt.h.

    Read the article

  • struct to bytes

    - by Dave18
    I'm trying to read encrypted struct data from file using fread(). once i get the decrypted struct bytes, I'd like to it put them back into this struct. struct data { string s1; string s2; string s3; long l; }; how would you convert a struct into bytes which can be reconstructed from bytes?

    Read the article

  • Multiplying matrices: error: expected primary-expression before 'struct'

    - by justin
    I am trying to write a program that is supposed to multiply matrices using threads. I am supposed to fill the matrices using random numbers in a thread. I am compiling in g++ and using PTHREADS. I have also created a struct to pass the data from my command line input to the thread so it can generate the matrix of random numbers. The sizes of the two matrices are also passed in the command line as well. I keep getting: main.cpp:7: error: expected primary-expression before 'struct' my code @ line 7 =: struct a{ int Arow; int Acol; int low; int high; }; My inpust are : Sizes of two matrices ( 4 arguments) high and low ranges in which o generate the random numbers between. Complete code: [headers] using namespace std; void *matrixACreate(struct *); void *status; int main(int argc, char * argv[]) { int Arow = atoi(argv[1]); // Matrix A int Acol = atoi(argv[2]); // WxX int Brow = atoi(argv[3]); // Matrix B int Bcol = atoi(argv[4]); // XxZ, int low = atoi(argv[5]); // Range low int high = atoi(argv[6]); struct a{ int Arow; // Matrix A int Acol; // WxX int low; // Range low int high; }; pthread_t matrixAthread; //pthread_t matrixBthread; pthread_t runner; int error, retValue; if (Acol != Brow) { cout << " This matrix cannot be multiplied. FAIL" << endl; return 0; } error = pthread_create(&matrixAthread, NULL, matrixACreate, struct *a); //error = pthread_create(&matrixAthread, NULL, matrixBCreate, sendB); retValue = pthread_join(matrixAthread, &status); //retValue = pthread_join(matrixBthread, &status); return 0; } void matrixACreate(struct * a) { struct a *data = (struct a *) malloc(sizeof(struct a)); data->Arow = Arow; data->Acol = Acol; data->low = low; data->high = high; int range = ((high - low) + 1); cout << Arow << endl<< Acol << endl; }// just trying to print to see if I am in the thread

    Read the article

  • C#: Struct Constructor: "fields must be fully assigned before control is returned to the caller."

    - by Rosarch
    Here is a struct I am trying to write: public struct AttackTraits { public AttackTraits(double probability, int damage, float distance) { Probability = probability; Distance = distance; Damage = damage; } private double probability; public double Probability { get { return probability; } set { if (value > 1 || value < 0) { throw new ArgumentOutOfRangeException("Probability values must be in the range [0, 1]"); } probability = value; } } public int Damage { get; set; } public float Distance { get; set; } } This results in the following compilation errors: The 'this' object cannot be used before all of its fields are assigned to Field 'AttackTraits.probability' must be fully assigned before control is returned to the caller Backing field for automatically implemented property 'AttackTraits.Damage' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer. Backing field for automatically implemented property 'AttackTraits.Distance' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer. What am I doing wrong?

    Read the article

  • Why Can I Change Struct's int[] Property from Method Without Specifying "ref"?

    - by AMissico
    From a method, I can pass a struct which contains an array of integers, and change the values in the array. I am not sure I understand fully why I can do this. Can someone please explain why I can change the values stored in the int[]? private void DoIt(){ SearchInfo a = new SearchInfo(); a.Index = 1; a.Map = new int[] { 1 }; SearchInfo b = new SearchInfo(); b.Index = 1; b.Map = new int[] { 1 }; ModifyA(a); ModifyB(ref b); Debug.Assert(a.Index == 1); Debug.Assert(a.Map[0] == 1, "why did this change?"); Debug.Assert(b.Index == 99); Debug.Assert(b.Map[0] == 99); } void ModifyA(SearchInfo a) { a.Index = 99; a.Map[0] = 99; } void ModifyB(ref SearchInfo b) { b.Index = 99; b.Map[0] = 99; } struct SearchInfo { public int[] Map; public int Index; }

    Read the article

  • How can I modify the value of a string defined in a struct?

    - by Eric
    Hi, I have the following code in c++: #define TAM 4000 #define NUMPAGS 512 struct pagina { bitset<12> direccion; char operacion; char permiso; string *dato; int numero; }; void crearPagina(pagina* pag[], int pos, int dir) { pagina * paginas = (pagina*)malloc(sizeof(char) * TAM); paginas -> direccion = bitset<12> (dir); paginas -> operacion = 'n'; paginas -> permiso = 'n'; string **tempDato = &paginas -> dato; char *temp = " "; **tempDato = temp; paginas -> numero = 0; pag[pos] = paginas; } I want to modify the value of the variable called "string *dato" in the struct pagina but, everytime I want to assing a new value, the compiler throws a segmentation fault. In this case I'm using a pointer to string, but I have also tried with a string. In a few words I want to do the following: pagina - dato = "test"; Any idea? Thanks in advance!!!

    Read the article

  • Overlaying several CLR reference fields with each other in explicit struct?

    - by thr
    Edit: I'm well aware of that this works very well with value types, my specific question is about using this for reference types. I've been tinkering around with structs in .NET/C#, and I just found out that you can do this: using System; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class Foo { } class Bar { } [StructLayout(LayoutKind.Explicit)] struct Overlaid { [FieldOffset(0)] public object AsObject; [FieldOffset(0)] public Foo AsFoo; [FieldOffset(0)] public Bar AsBar; } class Program { static void Main(string[] args) { var overlaid = new Overlaid(); overlaid.AsObject = new Bar(); Console.WriteLine(overlaid.AsBar); overlaid.AsObject = new Foo(); Console.WriteLine(overlaid.AsFoo); Console.ReadLine(); } } } Basically circumventing having to do dynamic casting during runtime by using a struct that has an explicit field layout and then accessing the object inside as it's correct type. Now my question is: Can this lead to memory leaks somehow, or any other undefined behavior inside the CLR? Or is this a fully supported convention that is usable without any issues? I'm aware that this is one of the darker corners of the CLR, and that this technique is only a viable option in very few specific cases.

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >