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.
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?
I'm trying to call a function via a function pointer, and this function pointer is inside a structure. The structure is being referenced via a structure pointer.
Code:
position = hash->(*funcHash)(idNmbr);
The function will return an int, which is what position is a type of. When I compile this code,
I get the error: error: expected identifier before ( token.
Is my syntax wrong? I'm not sure what would be throwing this error.
I have a nested record structure in C++ that contains a FileHeader record, a RecordHeader record and a DataRecord record. The last item is an array of unknown size (at compile time). I have to open a file and read the array size and then create the array.
I have worked on this for some time and can't figure out how to make it work. I know the sample data I am using has 85 records. I insert 85 into the array size and it works fine. But how do I create a dynamic array or define a vector within a nested structure?
1. What is the best (easiest) method to accomplish this (array or vector)? 2. How would it be implemented/how do you add data to it?
PreviousLogRecord.FaultRecord.push_back(field1); // does not work PreviousLogRecord.FaultRecord[recordNumber].field1 = somedata; // works with 85 in array size. struct LogFileHeaderRecordType { QString field1; int field2;
I've been able to write the program completing all requirements except for one... creating a function that accepts a nested structure array. Here's the program:
I am not able to assign value into struct addrinfo variable through struct sort_result structure variable.
struct addrinfo { int ai_flags; /* Input flags. */ int ai_family; /* Protocol family for socket. */ int ai_socktype; /* Socket type. */ int ai_protocol; /* Protocol for socket. */
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'
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 ?
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 ?
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;
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:
What are the workarounds for accessing the non-static member variables of some class(Say A) inside static member functions of another class(Say B)? I am coding in c++. Class A is derived with public properties of class B. Any pointers?
Example : Code: struct x { int v[4]; }; const x test = { 0, 1, 2, 3 };
Why can I do this? How does the compiler know to write to this in the proper way? I get that v would be contiguous. Does that have something to do with it?
Alright, so I have a code that's not giving me errors, but it doesn't seem to retain what I put into an array. Not sure If I'm missing something...
Code: #include <stdio.h> int main (void) { const char *pointer; const char alphabet[] = "ABCDEFG";
pointer = &alphabet[5]; printf("pointing to %c of the alphabet ", pointer); return 0; }
Trying to get my pointer to return the letter in the [5] spot or "F". Not receiving any errors when compiling, but I seem to get different answers every time I run it.