Hi,

I have used this

#using <System.dll>
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Linq;

SortedList<double, String^>^ slist = gcnew SortedList<double, String^>();

in one program its working well. But Now when I pasted the same code with all given headers in second program its not being identified there. Errors are coming.

'SortedList' : ambiguous symbol
1>could be 'c:\program files\reference assemblies\microsoft\framework\.netframework\v4.0\system.dll : System::Collections::Generic:: SortedList'
1>'c:\program files\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : System::Collections:: SortedList'


Any help why this error could be avoided. Thanks in advance for sparing time for me.

This is the complete program with two reference classes "message" and "exchange" whose code I haven't pasted here. PLEASE HELP

//#include<stdlib.h> 
#using <System.dll>
#using <mscorlib.dll>
#include "stdafx.h"
#include"stdio.h"
#include <msclr\marshal_cppstd.h>
using namespace System::Collections;
using namespace System;
#include<string.h>
using namespace std;
using namespace msclr::interop;
#include "message.h"
#include "exchange.h"
#include <vcclr.h>
#include <iostream>
using namespace System::Collections::Generic;
using namespace System::Linq;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int wildcmp(const char *wild, const char *string) {
  // comparing wilcard binding key with routing key
  const char *cp = nullptr, *mp = nullptr;
 
  while ((*string) && (*wild != '#')) {
          if ((*wild != *string) && (*wild != '*')) {
      return 0;
    }
    wild++;
    string++;
  }
 
  while (*string) {
          if (*wild == '#') {
      if (!*++wild) {
        return 1;
      }
      mp = wild;
      cp = string+1;
        } else if ((*wild == *string) || (*wild == '*')) {
      wild++;
      string++;
    } else {
      wild = mp;
      string = cp++;
    }
  }
 
  while (*wild == '#') {
    wild++;
  }
  return !*wild;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct ListNode
{
   ListNode(gcroot<message^> msg);
   gcroot<message^> msg;
  
    ListNode* next;
};
 
ListNode::ListNode(gcroot<message^> msg): msg(msg), next(nullptr) {}
 
public class queue
{
public:
    queue();
    ~queue();
    bool Empty() const;
    //int Next() const;
    void Enqueue(message^);
    void Dequeue();
        void DisplayAll() const;
        void setbinding(String^);
        String^ getbinding(void);
private:
    // Disable copying to keep the example simple
        gcroot<String^> bindingkey;
        queue(queue const& obj);
  
    ListNode* head;
    ListNode* tail;
};
 
queue::queue():head(nullptr), tail(nullptr) {}
 
queue::~queue()
{
    while (head != nullptr)
    {
        Dequeue();
    }
}
 

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);
    }
}
 
void queue::setbinding(String^ m)
  {
     bindingkey = m;
  }
 
String^ queue::getbinding()
  {
     return bindingkey;
  }
 
/////////////////////////////////////////////////////////////////queue List class//////////////////////////////////////////////
struct ListQueue
{
   ListQueue(queue* que);
    queue* que;  
   ListQueue* next;
}; ListQueue::ListQueue(queue* que): que(que), next(nullptr) {}
 
class queueL
{
public:
    queueL();
    ~queueL();
  
    void addqueue(queue*); 
       void Dequeue();
    void search(exchange^, message^);
      
private:
    // Disable copying to keep the example simple
 
    queueL(queueL const& obj);  
    ListQueue* start;
    ListQueue* end;
};
 
queueL::queueL():start(nullptr), end(nullptr) {}
 
queueL::~queueL()
{
    while (start != nullptr)
    {
        Dequeue();
    }
}
 
void queueL::addqueue(queue* que)
{
   if (start == nullptr)
    {
        start = end = new ListQueue(que);
    }
    else
    {
        end->next = new ListQueue(que);
        end = end->next;
    }
}
 
void queueL::Dequeue()
{
    ListQueue* temp = start->next;
    delete start;
    start = temp;
}
 
 
void queueL::search(exchange^ ex, message^ m)
{
System::String^ b;
  for (ListQueue* list = start; list; list = list->next)
    {
          b=list->que->getbinding();
         if((b->Equals(m->routingk))&&(ex->exchange_name=="Direct"))
         {
       
                list->que->Enqueue(m);
               // Console::WriteLine("the condition is true");
         }
       else if(ex->exchange_name=="fanout")
          {
             list->que->Enqueue(m);
           //Console::WriteLine("the condition is not true");
          }
         else if(ex->exchange_name=="TOPIC")
          {
             std::string a = "test";    
                a= marshal_as<std::string>(b); // converting managed binding key to std::string
                     const char * aa = a.c_str();    //now std:string to const char*
            // cout << "Hello!" << a<< endl;
                     std::string rr = "test1";
                     rr= marshal_as<std::string>(m->getType());
                     const char * rrr = rr.c_str();
 
                     if (wildcmp(aa,rrr))
                        {
                        //Console::WriteLine("match found");
                        list->que->Enqueue(m);
                        }
                     // else
                 //Console::WriteLine("match not found");
                         
           }
        //Console::WriteLine("the binding key of queue is {0}",b);
 
      }
//  Console::WriteLine("the last queue's binding key is {0}",b);
}


int main(array<System::String ^> ^args)
{

SortedList<double, String^>^ slist = gcnew SortedList<double, String^>();
  

      
       //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;
 
  // defining binding key of the queue by the function in the queue
  usa->setbinding("usa.#");
  weather->setbinding("usa.weather");
  news->setbinding("#.news");
  europe->setbinding("europe.#");
 
  //Inserting one message in weather queue
   weather->Enqueue(gcnew message("*144"));
 
  //Inserting one message in europe queue
 
   news->Enqueue(gcnew message("pak.nasdaq"));
 
   //Inserting one message in usa queue
   // head=tail=nullptr;
  usa->Enqueue(gcnew message("uk.nasdaq"));
  usa->Enqueue(gcnew message("uk.n"));
 
  //obj is a linked list of queues
  queueL obj;
  obj.addqueue(usa);
  obj.addqueue(weather);
  obj.addqueue(news);
  obj.addqueue(europe);
// declaring messages and exchanges
  message^ m = gcnew message("usa.weather");
  exchange^ direct= gcnew exchange("Direct");
  message^ m2 = gcnew message("weather.europe");
  message^ m1 = gcnew message("usa.news");    //message to check for topic exchange
  exchange^ fan= gcnew exchange("fanout");
  exchange^ topic = gcnew exchange("TOPIC");
  obj.search(direct,m);
  obj.search(fan,m1);
  obj.search(topic,m1);
 
  Console::WriteLine("the items in the queue 'news' are");
  news->DisplayAll();
  Console::WriteLine("the items in the queue 'weather' are");
  weather->DisplayAll();
  Console::WriteLine("the items in the queue 'usa' are");
  usa->DisplayAll();
Console::ReadLine();
 
}

What is this code supposed to do?
There are a lot of things that can be corrected, but I need to know what is the most important thing or what is the charter of the program.

It looks like if you stick to either CLI or STL, you can get this done.

Can you please explain. Why Sorted list only creating problems...

What I'm saying is that is not the only problem with this code.

If you fully-qualify the SortedList, does it help?

System::Collections::Generic::SortedList<double, String^>^ slist = gcnew System::Collections::Generic::SortedList<double, String^>();

Thanks , your help to design the code well would be highly appreciated.

this program is about sending messaging to queues on basis of different condition. I wanted to correct problems you finding in it. PLEASE HELP

Is your first problem fixed?

yes thanks

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.