Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with struct that name is pointer

Status
Not open for further replies.

benny143

Programmer
Joined
Mar 4, 2003
Messages
1
Location
US
I am having a problem accessing a struct, here is the code

typedef struct QueueStruct {
int Count; /* number of queue items */
void* Front; /* location of item to remove next */
void* Rear; /* place to insert next item */
}*QueueADT;



QueueADT QueueNew()
{

QueueADT *Q;

Q = new QueueADT ;
//t = **Q;
//(*Q)->Count = 0; /* Count == number of items in the queue */
//(*Q)->Front = NULL; /* Front == location of item to remove next */
//(*Q)->Rear = NULL; /* Rear == place to insert next item */

return *Q;
}

int main() {


using namespace std;

QueueADT q;

q = QueueNew();
q->Count = 0;


return 0;

Whenever I try and access and of the member variables I get an access denied message, it looks like I have the pointers setup incorrectly but I can't figure out what I doing wrong. Any help would be appreciated
 
hi Benny
see if it helps

#include <iostream.h>

//using namespace std;

typedef struct QueueStruct {
int Count; /* number of queue items */
void* Front; /* location of item to remove next */
void* Rear; /* place to insert next item */
QueueStruct(){ Count =0;
Front = NULL;
Rear = NULL;
}

} QueueADT;



QueueADT QueueNew()
{

QueueADT *Q;

Q = new QueueADT ;
//t = **Q;
//(*Q)->Count = 0; /* Count == number of items in the queue */
//(*Q)->Front = NULL; /* Front == location of item to remove next */
//(*Q)->Rear = NULL; /* Rear == place to insert next item */

return *Q;
}

int main()
{
QueueADT q;
q = QueueNew();
q.Count = 0;
return 0;
}
 
QueueADT QueueNew()
{

QueueADT Q; //Q is a pointer to structure of Type QueueStruct

Q = new QueueStruct ; //create a valid Queuestruct on the heap

return Q; //return the pointer
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top