C :: Set Struct Member Variable For Structure Inside Def
Mar 12, 2014
This is with Linux gcc
Code:
typedef struct _a
{
int id;
} a;
typedef struct _b
{
a my_a;
my_a.id = 1; // error: expected specifier-qualifier-list before "my_a"
} b;
I get error: expected specifier-qualifier-list before "my_a"
I must set the id for the kind of struct created inside the struct def because main() will be casting based on this id. Thats how I will know which structure b contains by it's id, there could be hundards of different structs with different values I will cast to the correct one and know it's members by it's id. How do I ?
View 10 Replies
ADVERTISEMENT
Oct 7, 2014
Is it possible to assign a value to structure member inside the structure.like.....
struct control{
char tbi:2 =0;
char res:1 =0;
};
View 6 Replies
View Related
Aug 27, 2013
I am trying to run a programme implementing a function with structures in c... which is:
#include<stdio.h>
#include<conio.h>
struct store {
char name[20];
float price;
int quantity;
[Code] .....
View 1 Replies
View Related
Jan 18, 2013
I have a question regarding composition and accessing members "deep" inside the composed structure. For example;
class A {
private:
int m_myInt;
public:
int myInt() const {return this->m_myInt;};
void myInt(int newInt) {this->m_myInt = newInt;};
[Code] ....
Now, from somwhere I have access to an object of type B where I want to update the A::m_myInt. How would you do this without "breaking" the whole purpose of private/public members?
B myB;
myB.m_a.myInt(3); // Not allowed, and not desireable
I thought about implementing access through functons kind of like;
A & B::a() {return this->m_a;};
myB.a().myInt(3);
but I'm worried that this exposes my B::m_a-object too much. This would allow
myB.a() = A();
, right?
The following is a more desireable way of acces, but doesn't work for updating;
A const & B::a() {return this->m_a;};
myB.a().myInt(3); //Disallowed? myInt(int) is non-const.
What about this? Is this a good way of doing it?
class A {
private:
int m_myInt;
public:
int myInt() const {return this->m_myInt;};
[Code] ....
I guess it works? It would lead to a lot of data shuffling in case of larger sub-components.I would really like to do the following without exposing my components so much:
B myB;
myB.a().myInt(3);
Can it be done?
View 11 Replies
View Related
Jun 20, 2013
I have the code bellow, and i print the data but cannot assign it to global variable.
struct frequency_data {
char frequency[10];
int32 frequenca_mesatare;
int16 PWM_F;
int32 PR2;
[Code] ....
View 5 Replies
View Related
Jun 5, 2012
"
#include <stdio.h>
struct datastructure {
char character;
};
void function(struct datastructure** ptr);
[Code] ....
These codes give these errors:
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
These errors are related to
"
*ptr->character='a';
printf("Ptr: %c",*ptr->character);
"
I want to access "character" data inside the structure "trial" by a pointer to pointer "ptr" inside function "function",but I couldn't find a way to do this.
View 3 Replies
View Related
Jul 20, 2013
Say you had:
class Foo{
public:
//...
void funky();
[Code] .....
Would each instance of Foo create a new counter variable, or would it remain the same for all of them, i.e. baz.funky() would always use the same counter variable? What if the class was a template?
View 3 Replies
View Related
Feb 10, 2013
I am modifying a set of static variables inside of the class's member function. The static variables are private. An example of what I'm doing is as below,
utilities.h
-----------
class utilities {
private:
static int num_nodes;
public:
void parse_details(char* );
[Code] ....
I get a compilation error in the function void utilities::parse_details(char* filename)
which says: undefined reference to `utilities::num_nodes'
compiler: g++
View 2 Replies
View Related
Dec 7, 2014
Why doesn't this compile?
struct hi(){
void other();
}histructure;
void hi::other(){
std::cout << "Hi!" << std::endl;
[Code] ....
Makes no sense the structure is written before the structure member function is called so why is there compile errors ??...
View 3 Replies
View Related
Aug 31, 2014
So I have a class object that contains the private member variable spot and the public member function MoveLock. Within MoveLock, is a member variable called numbers that holds the place where a user is on a "lock knob". Now, what I'm trying to accomplish is that whenever the user turns the "knob" in the wrong direction, the position is updated with that current numbers so that the clicks needed to unlock the first state is also updated. But I get these errors:
Error E2096 C:Users...switchtest.cpp 34: Illegal structure operation in function main()
Error E2294 C:Users...switchtest.cpp 39: Structure required on left side of . or .* in function main()
Ultimately, what I have in main() is a piece of what I'm going to implement in a class member function. I'm also thinking about moving the if else statements out of the for and creating a second one for the else portion.
#include <iostream>
#include <windows.h>
#include <iomanip>
using namespace std;
HANDLE inKeys = GetStdHandle(STD_INPUT_HANDLE);
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
[code]....
View 10 Replies
View Related
Jun 23, 2013
while writing code i got a question. For example i created a class named as unit.
Think a simple game, and the unit class will belong the units.İf i give the preferences as private one by one, it will be irregular. For a detailed game; height, weight, race, hair preferences, eyes... Strength, dexterity, charisma, intelligence, wisdom, constution... experience, damage, armor...
and should i use struct to group them? And how to can i use struct at the inside of class as private?
View 2 Replies
View Related
Aug 7, 2013
Let me say I have a structure
Code:
struct time{
char hours;
char minutes;
char seconds;
char dummy;
};
I have kept dummy as the data to be aligned.I will update hours, minutes, and seconds , but will not use dummy in any case. If I don't initialize 'dummy' does it make any errors ? Do I need to initialize hours, minutes, seconds as well before I use the structure ? If so is there any particular reason ?
View 7 Replies
View Related
May 1, 2013
I am having trouble compiling my interface. I am trying to store a reference variable as a member variable of the interface object. Compiler says that the variable has not be initiated correctly.
LCD inherits from VisualInterface which is expecting a DisplayDriver object to be passed in (DisplayDriver is another interface, but thats not important).
I pass the displayDriver object in when LCD is instantiated in maininterfaces.zip
I was pasing it before as a pointer but was told that this could cause me problems with memory leaks and a reference was better, but now I cant seem to get it to compile.
View 11 Replies
View Related
Mar 5, 2014
I want to define enumeration inside a structure and use it in some other file
for eg
header.h
typedef struct dummy {
typedef enum {
ZERO,
ONE,
MAX
} NUMBERS;
// some member variables
} DUMMY; // end of the structure
otherfile.cpp
in this file i want to access both enumerations(for eg) ONE as well as the type NUMBERS.
View 1 Replies
View Related
Apr 22, 2014
#include <stdio.h>
#include <string.h>
#define MAX 22
struct inven {
int Iid;
double uprice;
int uoh;
char name[MAX];
[code].....
doesn't seem to want to display the disp* fucntions at all
View 2 Replies
View Related
Mar 19, 2014
i had a structure as follows:
struct a{
int x;
struct b{
int y;
b *next;
}b;
};
when i try to access as follows:
struct a *a;
a->b=a->b->next;
i got the following error: base operand of ‘->’ has non-pointer type
View 1 Replies
View Related
Dec 27, 2012
I have some problem while allocating memory to a union inside structure. Below is the code i am using
ON SYSTEM1:
This works fine
ON SYSTEM2:
compiler complains saying "need structure or union type" while allocating MYSTRUCT1.
If I change:
shreyas[0].UnionAttr.struct1 = (MYSTRUCT1 *) malloc (sizeof(MYSTRUCT1)
to
shreyas[0].UnionAttr->struct1 = (MYSTRUCT1 *) malloc (sizeof(MYSTRUCT1)
This compiler on SYSTEM2 is happy. but second way does not look correct to me and compiler on system 1 complains about it. Which is the correct way to allocate memory?
If first one is correct then what should i look in for to avoid this error? Could this be an issue with compiler on SYSTEM2? If i use second method on SYSTEM2 code segfaults during malloc.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct mystruct1 {
int a;
int b;
[Code] ....
View 3 Replies
View Related
Aug 25, 2014
I want to have a function pointer inside a typedef struct but I get a segmentation fault when I run my code. Here's my code:
#include <stdio.h>
typedef struct Foo {
void (*bar)(int);
} Foo;
void func(int x) {
printf("display: %d
[Code] ....
View 2 Replies
View Related
Feb 13, 2015
How can I display the elements of an array inside struct something like this
struct ABC {
double a[3];}
void show( const ABC & x );
ABC x{18, 'W', { 1.1, 2.2, 3.3 }};
show(x); would output {18, ‘W’, {1.1, 2.2, 3.3}}
View 10 Replies
View Related
Jul 22, 2013
Can typedef and struct be put inside a class like below?
Code:
class classA {
private:
typedef void(classA::*aFnPtr_t) (); //pointer-to-member function
struct strctA {
int a;
int b[100];
};
typedef struct strctA strctA_t;
typedef void (classA::*bFnPtr_t)(strctA_t*); //pointer-to-member function
...
}
View 8 Replies
View Related
Mar 21, 2013
If I wanted to call a member function inside another member function, how would I do that, if it's possible?
For example, if I have Find(int key) defined already and wanted to call it while i was overloading operator+.
View 2 Replies
View Related
Apr 24, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct info info;
[Code] ....
View 2 Replies
View Related
Feb 22, 2013
I have two classes, a Package class and a Person class. The Package class has two Person objects has member variables, a Sender and a Receiver. While overloading the << operator for the Package class so that it will make an output label from everything in the Package class. Here is my code...
class Package{
public:
Person Sender;
Person Reciever;
int weight;
double cost;
friend ostream &operator<<(ostream &out, Package &pack);
[Code] .....
So my problem is on that last output line, I am unable to call Sender.getName()... etc. Is there a proper syntax so that I can access the members of the Person class while overloading the << operator for the Package class?
View 2 Replies
View Related
Jan 7, 2015
I have started working with structures so here's a side project from my text book. It's purpose is fairly simple; it asks for the sales of each quarter of the year from 4 different divisions and then calculates the average quarterly sales and total annual sales and finally displays all the data. My problem is that in the function "displayCompanyInfo" the statement
std::cout << "Division " << R.division_name << std::endl;
does not display the name of the division. With that in mind here is the code:
#include <iostream>
#include <string>
struct CompanyInfo
{
[Code]....
As you can see the last part of the output has statements that say "Division" however they do not say the name of the division afterwards. I don't understand why that is?
View 2 Replies
View Related
Feb 17, 2015
See the simple code below. The compiler gives message:
assigning to type "char[20]" from type "char *".
I've tried everything else that seems reasonable but none works. How can I assign string Hello to the structure member?
Code:
int main() {
struct strc1
{
char msg1[20];
char msg2[5];
}
talk;
talk.msg1 = "Hello";
}
View 5 Replies
View Related
Mar 24, 2014
is it possible to make something like that?
struct type_name
{
char Status[i];
string Status[j];
.
.
} object_names;
The problem is I dont know how many statuses my object will have. Is it possible to make it in an dynamic array?
View 3 Replies
View Related