views:

34

answers:

1

Doing Managed C++ in VS2008. Have a vendor defined data structure as follows:

class API TF_StringList
{
public:
  TF_StringList(const char* encoding = "cp_1252");

 ~TF_StringList();

 TF_String* first_string() const {return start_string;}
 TF_String* last_string() const {return end_string;}

 void insert(const TF_String& aString);
 void insert(const char* aString);  

 // If the length parameter is larger than the size of the string,
 // The behavior is uncertain.
 void insert(const tf_Byte* aString, size_t aByteLength);

 void clear();

 size_t size() const { return list_size; }

 char* character_encoding;

private:

 void set_first(TF_String* stringPtr) {start_string = stringPtr;}
 void set_last (TF_String* stringPtr) {end_string = stringPtr;}

 TF_String* start_string;
 TF_String* end_string;
 TF_String* curr_pos;
 size_t list_size;


 // Do not expose the copy constructor and the assignment operator.
 TF_StringList(const TF_StringList& tmp);
 TF_StringList& operator=(const TF_StringList& tmp);

};

In one of my managed functions I have parameter of List<String^> categoryList and I want to load an object of type TF_StringList with the elements of that parameter.

//Instantiate the TF_StringList
categories = new TF_StringList();
for(int i=0; i<categoryList.Count; i++)
{
   const char* str = (char*)(Marshal::StringToHGlobalAnsi(categoryList[i])).ToPointer();
   categories->insert(str);
}

The error I get is: error C2663: 'TF_StringList::insert' : 3 overloads have no legal conversion for 'this' pointer

What have I done wrong? Jim

A: 

Ok, I see a few possibilities: First, if I need a const char* I need to cast to one so I've change:

const char str = (char*)(Marshal::StringToHGlobalAnsi(categoryList[i])).ToPointer();

to:

const char str = (const char*).....;  

this didn't change the error.

Second, The error would lead me to believe that str is not "seen" by the TF_StringList instance as a const char* since the insert(const char* aString) does not accept it.

Third, the list does not index out a Managed String (e.g. that String^ st = categoryList[i] is not valid). This seems unlikely since the declaration is List categoryList.

How can I check to find out what the problem actually is?

Jim Jones