I am making a game using C# with the XNA framework. The player is a 2D soldier on screen and the user is able to fire bullets. The bullets are stored in an array. I have looked into using Lists and arrays for this and I came to the conclusion that an array is a lot better for me, as there will be a lot of bullets firing and being destroy...
If I have a struct with a fieldname 'fieldname', is it possible to access the data in that field using only the variable?
ie.
x = 'fieldname'
is it possible to do
data = struct.(x) in some way? I want to use the string in x as the field name.
...
Hi I am working on a program where I have to initialize a deck of cards. I am using a struct to represent a card. However I'm not filling it correctly as I get a bunch of zero's when I display the deck of cards. I believe my mistake is in this line but I'm not sure:
struct card temp = {"Clubs", value, false};
The code:
void initCard...
I have 2 structures that have 90% of their fields the same. I want to group those fields in a structure but I do not want to use the dot operator to access them. The reason is I already coded with the first structure and have just created the second one.
before:
typedef struct{
int a;
int b;
int c;
object1 name;
} str1;
...
Hello everyone!
I am currently working on a simple Scrabble implementation for a college project.
I can't get a part of it to work, though!
Check this out:
My board.h:
http://pastebin.com/J9t8VvvB
The subroutine where the error lies:
//Following snippet contained in board.cpp
//I believe the function is self-explanatory...
//Pos i...
I'm trying to figure out how to access a matrix that is stored in a field in a matlab structure from a mex function.
That's awfully long winded... Let me explain:
I have a matlab struct that was defined like the following:
matrixStruct = struct('matrix', {4, 4, 4; 5, 5, 5; 6, 6 ,6})
I have a mex function in which I would like to be...
Update: I have filed a bug report with Microsoft Connect, please vote for it!
Update 2: Microsoft have marked the bug report as fixed
Posted by Microsoft on 18/08/2010 at 17:25
This bug will be fixed in a
future version of the runtime. I'm
afraid it's too early to tell if that
will be in a service pack or the next
major...
I can't seem to figure out the syntax for finding structs in containers.
I have a multiset of Event structs. I'm trying to find one of these structs by searching on its key. I get the compiler error commented below.
struct Event {
public:
bool operator < ( const Event & rhs ) const {
return ( time < rhs.time );
}
bool operat...
My Struct Definitions.
typedef struct inner_list {char word[100]; inner_list*next;} inner_list;
typedef struct outer_list
{ char word [100];
inner_list * head;
outer_list * next; } outer_list;
And The problem part:
void append(outer_list **q,char num[100],inner_list *p)
{ outer_list *temp,*r;
temp = *q;
char *str;
...
I'm trying to make a program with structs and files. The following is just a part of my code(it;s not the entire program).
What i'm trying to do is: ask the user to write his command. eg. delete John
eg. enter John James 5000 ipad purchase.
The problem is that I want to split the command in order to save its 'args' for a struct element...
My questions are in the code, but basically i want to know how/if I can do the two commented out lines? I know I can do it in a constructor but I don't want to!
struct foo
{
int b[4];
} boo;
//boo.b[] = {7, 6, 5, 4}; // <- why doesn't this work? (syntax error : ']')
//boo.b = {7, 6, 5, 4}; // <- or else this? (syntax error : '{')
...
Oftentimes data structures' valid initialization is to set all members to zero. Even when programming in C++, one may need to interface with an external API for which this is the case.
Is there any practical difference between:
some_struct s;
memset(&s, 0, sizeof(s));
and simply
some_struct s = { 0 };
Do folks find themselves usi...
As an addendum to this question, what is going on here:
#include <string>
using namespace std;
struct A {
string s;
};
int main() {
A a = {0};
}
Obviously, you can't set a std::string to zero. Can someone provide an explanation (backed with references to the C++ Standard, please) about what is actually supposed to happen her...
I'm writing a simple program which is about polynomials using linked 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. How do I fix that? Here is my struct:
struct poly { public int coef; public int pow; public poly* link;} ;
An...
I have an array of users that's sorted in descending order based on total_points.
I need to find the rank of each user in that array. The issue is that more than one user can have the same total points and, thus, the same rank. For example, three users could be in 3rd place with 200 Points. Here's my current code:
class Leader < Act...
I read about unions the other day( today ) and tried the sample functions that came with them. Easy enough, but the result was clear and utter garbage.
The first example is:
union Test
{
int Int;
struct
{
char byte1;
char byte2;
char byte3;
char byte4;
} Bytes;
};
where an int is as...
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:
all_...
struct t_empty {
};
This appears to compile properly in C++ but not C. (at least with the TI 28xx DSP compiler, where it emits the error "expected a declaration") Is this mentioned somewhere in the C standards, or is my compiler broken?
...
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 a struct that's defined with a large number of vanilla char* pointers, but also an object member. When I try to statically initialize such a struct, I get a compiler error.
typedef struct
{
const char* pszA;
// ... snip ...
const char* pszZ;
SomeObject obj;
} example_struct;
// I only want to assign the first f...