Say I have a struct that looks like this (a POD):
struct Foo
{
int i;
double d;
};
What are the differences between the following two lines:
Foo* f1 = new Foo;
Foo* f2 = new Foo();
Consider the following simple immutable struct:
struct Stash {
public int X { get; private set; }
public Stash(int _x) {
X = _x;
}
}
This is not working, because the compiler wants me to initialize the "backing field" before I can access the property. How can I solve this?
I have a class definition of the form
class X
{
public:
//class functions
private:
A_type *A;
//other class variables
};
and struct A_type is defined as
struct A_type
{
string s1,s2,s3;
};
Inside the constructor, I allocate appropriate memory for A and try A[0].s1="somestring";
It shows segmentation fault.
Is this kind…
I've looked for overriding guidelines for structs, but all I can find is for classes.
At first I thought I wouldn't have to check to see if the passed object was null, as structs are value types and can't be null. But now that I come to think of it, as equals signature is
public bool Equals(object obj)
it seems there is nothing preventing the…
Hi,
In the ARM ABI documentation I come across functions defined like:
__value_in_regs struct bar foo(int a, int b) {
...
}
but GCC(4.3.3) doesn't allow it and all I could find are references to some RealView compiler.
Is there any way of doing this from GCC?
I have tried -freg-struct-return but it doesn't make a difference. As it is an…
I have an MVC application. The model has a property that is a struct NSSize. It is writable like this:
- (void)setSize:(NSSize)aSize;
The view sets this NSSize using key-value-coding. However, you can not key-value-code a struct, so I wrapped it in an NSValue-object like this:
[theView setValue:[NSValue valueWithSize:mySize]
…
Hello, I'm writing a FUSE plugin in C. I'm keeping track of data structures in the filesystem through structs like:
typedef struct {
block_number_t inode;
filename_t filename; //char[SOME_SIZE]
some_other_field_t other_field;
} fs_directory_table_item_t;
Obviously, I have to read (write) these structs from (to) disk at some…
Hi
I am using ms c++. I am using struct like
struct header {
unsigned port : 16;
unsigned destport : 16;
unsigned not_used : 7;
unsigned packet_length : 9;
};
struct header HR;
here this value of header i need to put in separate char array.
i did memcpy(&REQUEST[0], &HR,…
I have an array of users who are friends. Let us call this array:
friends
I then have an array of structs. Each struct has a user object as an attribute (it also has a rank attribute). Here's what the struct class looks like, to add some context:
class Leader < Struct.new(:rank, :user); end
Let us call this array of structs:
…
I need a way to write structures of three different kinds to a binary file, which later has to be searched. (As in, for example, struct A has two fields, an int and a char; struct B has int and a long; I need to output all structures whose int equals the one given from keyboard).
I understand how to write structs of the same kind to a…
I have one problem with this code. I should create one structure and share it across 5 new process created from the father:
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include…
I am trying to use SWIG in order to use the Spotify API (libspotify) for Android: https://developer.spotify.com/technologies/libspotify/
I am having trouble defining the SWIG interface file to be able to successfully call the following native C function:
sp_error sp_session_create(const sp_session_config * config,…
Is it ok to have public data members in a C++ class/struct in certain particular situations?
How would that go along with inheritance?
I've read opinions on the matter, some stated already here
http://stackoverflow.com/questions/952907/practices-on-when-to-implement-accessors-on-private-member-variables-rather-than…
I hope the title is describing the problem, i'll change it if anyone has a better idea.
I'm storing information in a struct like this:
struct AnyStruct
{
AnyStruct :
testInt(20),
testDouble(100.01),
testBool1(true),
testBool2(false),
testBool3(true),
testChar('x')…
For example in C I have structure:
typedef struct {
int number;
double x1;
double y1;
double x2;
double y2;
double x3;
double y3;
} CTRstruct;`
Then I write it to file fwrite(&tr, 1, sizeof(tr), fp); (tr - its CTRstruct var, fp - File pointer);
Then I need to read it with Java! I…
I have about 1500 files on a share for which I need to collect FileVersionInfo string. So I created a Static method in my Gateway like this:
private static string GetVersionInfo(string filepath)
{
FileVersionInfo verInfo = FileVersionInfo.GetVersionInfo(filepath);
return string.Format("{0}.{1}.{2}.{3}",…
The Code that follows segfaults on the call to strncpy and I can't see what I am doing wrong. I need another set of eyes to look it this. Essentially I am trying to alloc memory for a struct that is pointed to by an element in a array of pointers to struct.
#include <stdio.h>
#include <stdlib.h>…
the following code reads an input array, and constructs a BST from it. if the current arr[i] is a duplicate, of a node in the tree, then arr[i] is discarded. count in the struct node refers to the number of times a number appears in the array. fi refers to the first index of the element found in the array.…
Hi,
I am working on a query processor that reads in long lists of document id's from memory and looks for matching id's. When it finds one, it creates a DOC struct containing the docid (an int) and the document's rank (a double) and pushes it on to a priority queue. My problem is that when the word(s)…
I have two arrays of structs.
array_of_structs1
array_of_structs2
The struct class looks like this, for contextual info:
class Leader < Struct.new(:rank, :user); end
I want to remove the duplicate users from array_of_structs1.
Any assistance would be greatly appreciated!
I have been struggling for too long a time now with a rather simple question about how to create a generic linked list in c++. The list should be able contain several types of structs, but each list will only contain one type of struct. The problem arises when I want to implement the getNode() function…
I'm fiddling with calling DLLs from C#, and came across the need to define my own structs. Lots of articles force a sequential layout for the struct with
[StructLayout(LayoutKind.Sequential)]
struct Foo ...
So, I followed suite, and my programme worked. Now, when I took the line out, it still…
I have an array of structs called leaders. The struct class looks like this, for contextual info:
class Leader < Struct.new(:rank, :user); end
Two questions:
How do I sort the array of structs by rank?
How do I sort the array of structs by rank and by user.created_at?