I have queue class as below

public class queue
{
public:
    queue();
    ~queue();
    bool Empty() const;
    void Enqueue(message^);
    void Dequeue();
        void DisplayAll() const;
    private:
        gcroot<String^> bindingkey;
        queue(queue const& obj);

    ListNode* head;
    ListNode* tail;
};

queue::queue():head(nullptr), tail(nullptr) {}

queue::~queue()
{
    while (head != nullptr)
    {
        Dequeue();
    }
}

//bool queue::Empty() const
//{
//    return head == nullptr;
//}

//String^ queue::Next() const
//{
//    return head->msg;
//}

void queue::Enqueue(message^ key)
{
    if (head == nullptr)
    {
        head = tail = new ListNode(key);
    }
    else
    {
        tail->next = new ListNode(key);
        tail = tail->next;
    }
}

void queue::Dequeue()
{
    ListNode* temp = head->next;
    delete head;
    head = temp;
}

void queue::DisplayAll() const
{
    for (ListNode* p = head; p; p = p->next)
    {
                Console::WriteLine("the element is {0}", p->msg->routingk);
    }

}


int main(array<System::String^> ^args)
{
  //four queues are created and added to the list of the queues
   queue *usa = new queue;
   queue *weather = new queue;
   queue *news = new queue;
   queue *europe = new queue;
 }

Can I have the name of the queue as STRING. PLEASE HELP.

Recommended Answers

All 6 Replies

Hello! I don't really understand your question. Do you want to programatically get the name of the pointer that points to a certain queue object? I think that could be rather tricky. What are you gonna use this for? I'm sure there's another way to solve your problem.

Regards,
Emil Olofsson

Thanks for reply, I want to store the name of the queue like usa, weather as strings.

Thanks for reply, I want to strore the name of the queue like usa, weather as strings.

Yes Emil you are right that what I want. To programatically get the name of the pointer that points to a certain queue object and store it as string.How can I do this please help.

as far as i could understand ur question (if correctly), that wot u r trying to do.. try creating another structure, and add some 'char *name' and 'queue Q' *as its data members. then if u create an array of that 'stucture type', u'll have an instance of queue at each index, along with " *name" wich u may use to correspond to each queue...

there can be many other ways too :)

commented: Thanks for your help I appreciate your answer. +1

Thanks for answer. Can you explain it with some coding please. What other ideas you think suit best with the situation.

You could add a member called name of type char*to your queue class. Then you could change the constructor to request a string that will be the name of your list:

public class queue
{
    public:
    queue();
    ~queue();
    bool Empty() const;
    void Enqueue(message^);
    void Dequeue();
    void DisplayAll() const;
    private:
    gcroot<String^> bindingkey;
    queue(queue const& obj);
    ListNode* head;
    ListNode* tail;
    char* name; // Added this
};

queue::queue(char* _name):head(nullptr), tail(nullptr), name(_name) {}

You can of course change it to some other string type if you would like that better. I hope it works!

commented: thanks +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.