| | |
Structure of Arrays in C++ using NEW operator
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2005
Posts: 6
Reputation:
Solved Threads: 0
HI guys,
This code dosn't compile, I think it is right but it gives an error when i use the -> to access the members of my struct.
#include <stdio.h>
#include <stddef.h>
#define MAX_EVENTS 100
//Structure for Queue Elements
struct Event
{
int event_type;
int time_value;
int bus_num;
int bus_stop;
};
void main()
{
Event *eventPtr;
// EventPtr event_queue;
eventPtr = new Event[MAX_EVENTS];
event_queue[0]->event_type = 1;
event_queue[0]->time_value = 2;
event_queue[0]->bus_num = 0;
event_queue[0]->bus_stop = 1;
}
It works when i create it without using the "new" operator. But this way it dosn't. WHat's going on here? I'm using the Visual C++ 6.0 compiler.
thanks..
This code dosn't compile, I think it is right but it gives an error when i use the -> to access the members of my struct.
#include <stdio.h>
#include <stddef.h>
#define MAX_EVENTS 100
//Structure for Queue Elements
struct Event
{
int event_type;
int time_value;
int bus_num;
int bus_stop;
};
void main()
{
Event *eventPtr;
// EventPtr event_queue;
eventPtr = new Event[MAX_EVENTS];
event_queue[0]->event_type = 1;
event_queue[0]->time_value = 2;
event_queue[0]->bus_num = 0;
event_queue[0]->bus_stop = 1;
}
It works when i create it without using the "new" operator. But this way it dosn't. WHat's going on here? I'm using the Visual C++ 6.0 compiler.
thanks..
Try this:
int main() { // EventPtr event_queue; Event *eventPtr; eventPtr = new Event[MAX_EVENTS]; eventPtr[0].event_type = 1; eventPtr[0].time_value = 2; eventPtr[0].bus_num = 0; eventPtr[0].bus_stop = 1; return 0; }
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Feb 2005
Posts: 6
Reputation:
Solved Threads: 0
I'm sorry, i cut and pasted the wrong thing last time. It should have pasted it like this.
#include <stdio.h>
#include <stddef.h>
#define MAX_EVENTS 100
//Structure for Queue Elements
struct Event
{
int event_type;
int time_value;
int bus_num;
int bus_stop;
};
void main()
{
Event *eventPtr;
eventPtr = new Event[MAX_EVENTS];
eventPtr[0]->event_type=1;
eventPtr[0]->time_value = 2;
eventPtr[0]->bus_num = 0;
eventPtr[0]->bus_stop = 1;
}
when i compile that it says. "error C2819: type 'Event' does not have an overloaded member 'operator ->'"
#include <stdio.h>
#include <stddef.h>
#define MAX_EVENTS 100
//Structure for Queue Elements
struct Event
{
int event_type;
int time_value;
int bus_num;
int bus_stop;
};
void main()
{
Event *eventPtr;
eventPtr = new Event[MAX_EVENTS];
eventPtr[0]->event_type=1;
eventPtr[0]->time_value = 2;
eventPtr[0]->bus_num = 0;
eventPtr[0]->bus_stop = 1;
}
when i compile that it says. "error C2819: type 'Event' does not have an overloaded member 'operator ->'"
•
•
Join Date: Feb 2005
Posts: 6
Reputation:
Solved Threads: 0
okay. thanks. I was just wondering why the -> operator wasn't working.
Also, would it be possible to create this same structure, but with a doubly linked ring, or a balanced tree? Instead of using arrays.
Links to already compilable data strucutres would be great. Professor said that is okay to use since it is not the focus of this program.
Also, would it be possible to create this same structure, but with a doubly linked ring, or a balanced tree? Instead of using arrays.
Links to already compilable data strucutres would be great. Professor said that is okay to use since it is not the focus of this program.
•
•
•
•
Originally Posted by F50
I was just wondering why the -> operator wasn't working.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- three dimensional arrays (PHP)
- build table used 2d arrays (C)
- Structure Help Please (C++)
Other Threads in the C++ Forum
- Previous Thread: Borland Compiler
- Next Thread: Help... assembly in Dev C++
Views: 14545 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






