mainQ->Enqueue(gcnew message(101));
mainQ->Enqueue(gcnew message(102));
mainQ->Enqueue(gcnew message(103));
I wanted to put just the objects of message class and it has one thing, That is "routing key" of the message.
mainQ->Enqueue(gcnew message(101));
mainQ->Enqueue(gcnew message(102));
mainQ->Enqueue(gcnew message(103));
I wanted to put just the objects of message class and it has one thing, That is "routing key" of the message.
And that technique works, right?
Not as such, Now I have thought to create the queue as linked list and put messages I have a working queue class, but as I tried to use the message class object "msg" into it as elements of queue.
its asking me
cannot declare a managed 'msg' in an unmanaged 'queue'. Can you please please help me what should I do. the code is as below:
// linkedlistqueue.cpp : main project file.
#include "stdafx.h"
#include"stdio.h"
using namespace System;
using namespace System::Collections;
#include "message.h"
class queue
{
message msg;
queue* next;
public:
queue* enqueue(queue*,int);
queue* dequeue(queue*);
void queue_display(queue*);
}*head,*tail,object;
queue* queue::enqueue(queue* head,message key)
{
queue* temp;
temp=new queue;
temp->element=key;
temp->next=nullptr;
if(head==nullptr)
head=temp;
else
tail->next=temp;
tail=temp;
return head;
}
//****************************************************
queue* queue::dequeue(queue* head)
{
queue* temp;
if(head==nullptr)
{
return nullptr;
}
else if(head->next==nullptr)
{
return nullptr;
}
else
{
//Console::WriteLine("the element that is dequeued {0}",head->element);
temp=head->next;
head=temp;
return head;
}
}
//***************************************************************
void queue::queue_display(queue* head)
{
if(head!=nullptr)
{
while(head->next!=nullptr)
{
Console::WriteLine(" the element is {0}",head->element);
head=head->next;
}
Console::WriteLine("{0}",head->element);
}
else
Console::WriteLine("the queue is empty");
}
void main()
{
head=tail=nullptr;
head=object.enqueue(head,(gcnew message(101)));
head=object.enqueue(head,(gcnew message(102)));
head=object.dequeue(head);
object.queue_display(head);
Console::ReadLine();
}
while the message class is same
public ref class message
{
public:
property int routingkey;
message(int Id)
{
routingkey = Id;
}
int message::getType()
{
return routingkey;
}
};
I solved it ! THANKS
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.