We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,394 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

HELP in getting the name of the queue class as string

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.

3
Contributors
6
Replies
2 Days
Discussion Span
1 Year Ago
Last Updated
7
Views
Question
Answered
SAM2012
Junior Poster in Training
63 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

emilo35
Junior Poster
104 posts since Feb 2010
Reputation Points: 14
Solved Threads: 12
Skill Endorsements: 0

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.

SAM2012
Junior Poster in Training
63 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

SAM2012
Junior Poster in Training
63 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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 :)

Z33shan
Light Poster
26 posts since Sep 2011
Reputation Points: 11
Solved Threads: 1
Skill Endorsements: 0

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

SAM2012
Junior Poster in Training
63 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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!

emilo35
Junior Poster
104 posts since Feb 2010
Reputation Points: 14
Solved Threads: 12
Skill Endorsements: 0
Question Answered as of 1 Year Ago by emilo35 and Z33shan

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0870 seconds using 2.75MB