CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2007
    Posts
    448

    List of errors when debug the application - please help!

    hi guys,

    I have a problem with the source code, when I tried to debug the application, I get the list of errors.

    The errors is:

    'System::Collections::Generic::List<T>::ToArray': function call missing argument list; use '&System::Collections::Generic::List<T>::ToArray' to create a pointer to member


    error C2955: 'System::Predicate' : use of class generic requires generic argument list

    error C2276: '&' : illegal operation on bound member function expression

    error C3350: 'System::Predicate' : a delegate constructor expects 2 argument(s)




    Code:
    private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
    				Random ^r = gcnew Random();
    				List<ListViewItem^> ^items = gcnew List<ListViewItem^>();
    
    				 for each (Match ^x1 in matches1)
    				 {
    					 array<String^> ^StrArr1 = x1->Value->ToString()->Split();
    					 items->Add(gcnew ListViewItem(gcnew array<String^> {x1->Value->ToString()->Replace("<p id='channel_name'>", "")->Replace("</p>", "")}));
    				 }
    				 ListView1->Items->AddRange(items->ToArray);
    }
    
    private: System::Void TextBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
    
    			Random ^r = gcnew Random();
    			List<ListViewItem^> ^items = gcnew List<ListViewItem^>();
    
    			 array<ListViewItem^> ^filteredItems = Array::FindAll(items->ToArray, gcnew System::Predicate(&isMatch));
    			 ListView1->Items->Clear();
    			 ListView1->Items->AddRange(filteredItems);
    		 }
    If you know how to fix the errors, I would be grateful.

    Thanks,
    Mark

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: List of errors when debug the application - please help!

    Quote Originally Posted by mark103 View Post
    I have a problem with the source code, when I tried to debug the application, I get the list of errors.
    I somehow doubt that you get those errors only when trying to debug. These are compiler errors that I would expect to be thrown during a release build as well.

    BTW, it would have been helpful if you had indicated on which code lines you got the errors.

    'System::Collections::Generic::List<T>::ToArray': function call missing argument list; use '&System::Collections::Generic::List<T>::ToArray' to create a pointer to member
    List<T>::ToArray() is a function, so yo need an empty pair of braces when you want to call it:

    Code:
    				 ListView1->Items->AddRange(items->ToArray());
    That's all the error message effectively means, though I must admit it's telling you that in a pretty cryptic way...

    error C2955: 'System::Predicate' : use of class generic requires generic argument list

    error C2276: '&' : illegal operation on bound member function expression
    error C3350: 'System::Predicate' : a delegate constructor expects 2 argument(s)
    These are all for the same code line, aren't they?

    The Predicate<T> delegate constructor requires you to explicitly specify the argument type that's passed to the predicate. And if the delegate "points" to a non-static member function of a class it indeed needs two parameters: The object handle to call the function on (in many cases this is this but not always) and a pointer-to-member to the function (which by its nature does not contain the object reference, thus the requirement for the first parameter).

    Code:
    			 array<ListViewItem^> ^filteredItems = Array::FindAll(items->ToArray(), gcnew System::Predicate<ListViewItem^>(this, &isMatch));
    I can only guess that isMatch() is a member of the same form class but I think it's likely, hence the this as the first parameter to the delegate constructor.

    I think the C2276 is a consequential error and pretty misleading. It should go away once you correct the other flaws.

    A bit puzzling is the fact that delegate constructors make do with a single parameter when used for a static member or free function.

    BTW...

    Code:
    				 array<String^> ^StrArr1 = x1->Value->ToString()->Split();
    The parameterless version of String::Split() is apparently undocumented on MSDN but it obviously is there and works. Where did you find it and by exactly which delimiters does it split?
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Aug 2007
    Posts
    448

    Re: List of errors when debug the application - please help!

    Thanks Eri523, I have replaced the code you have posted, but I am getting some errrors when I ran the debug.


    error C2276: '&' : illegal operation on bound member function expression

    error C3350: 'System::Predicate<T>' : a delegate constructor expects 2 argument(s)



    The error are jumping on this line:

    Code:
    array<ListViewItem^> ^filteredItems = Array::FindAll(items->ToArray(), gcnew System::Predicate<ListViewItem^>(this, &isMatch));
    do you know how to fix the errors that I am getting?

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Red face Re: List of errors when debug the application - please help!

    Oops! I actually anticipaded that error after writing my previous post. I intended to edit my post but I saw that you've been online since I did the post and so I decided to wait for a reaction from you. (Editing posts after the addressee as read them can be problematic because the edited post won't be displayed as new again to that user so chances are he/she misses the edit.)

    Try to qualify the class membership of the function to be called via the delegate:

    Code:
    array<ListViewItem^> ^filteredItems = Array::FindAll(items->ToArray(), gcnew System::Predicate<ListViewItem^>(this, &Form666::isMatch));
    Of course you'll replace Form666 with the name of your class containing the predicate function (regardless of whether it actually is a form or not, but I think it's likely to be a form).

    I think it was really easy to overlook: That's the 4th error on that very line... (Also, I always qualify member functions to be called via a delegate that way without really thinking about it conciously.)

    This time I think the C3350 is bogus and misleading: You obviously are passing two parameters to the delegate constructor. (And actually the C2276 is and was right and I was wrong yet again in post #2. )

    Thanks for clearly specifying the code line the errors belonged to this time. (EDIT: This may sound sarcastic considering there's only a single code line quoted in post #3. But be assured it's not meant that way. )

    BTW, an example of using Predicate<T> can be found in http://www.codeguru.com/forum/showthread.php?t=512194 (and I think it's more illustrative and practical than those I found on MSDN).
    Last edited by Eri523; May 28th, 2011 at 06:54 PM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  5. #5
    Join Date
    Aug 2007
    Posts
    448

    Re: List of errors when debug the application - please help!

    Thanks Eri523, I can see the problem has got rid of the errors, but I can't fill the data that I have extact from my website.


    Code:
    private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
    
    			 MessageBox::Show("timer starts now");
    			 timer1->Enabled = false;
    			 Form2 ^form7 = gcnew Form2();
    
    			 try
    			 {
    				 //Address of URL
    				 String ^URL = "http://www.mysite.com/Login.php?user=" + form2->ComboBox1->Text + "&pass=" + form2->TextBox1->Text;
    				 HttpWebRequest ^request = safe_cast<HttpWebRequest^>(WebRequest::Create(URL));
    				 HttpWebResponse ^response = safe_cast<HttpWebResponse^>(request->GetResponse());
    				 StreamReader ^reader = gcnew StreamReader(response->GetResponseStream());
    				 String ^str = reader->ReadToEnd();
    
    				 String ^pattern1 = "(<p id='myid1'>(.*?)</p>)";
    				 MatchCollection ^matches1 = Regex::Matches(str, pattern1);
    
    				Random ^r = gcnew Random();
    				List<ListViewItem^> ^items = gcnew List<ListViewItem^>();
    
    				 for each (Match ^x1 in matches1)
    				 {
    					 array<String^> ^StrArr1 = x1->Value->ToString()->Split();
    					 items->Add(gcnew ListViewItem(gcnew array<String^> {x1->Value->ToString()->Replace("<p id='myid1'>", "")->Replace("</p>", "")}));
    				 }
    				 ListView1->Items->AddRange(items->ToArray());
    			 }
    			 catch (Exception ^ex)
    			 {
    				 MessageBox::Show("the site you request is down!");
    			 }
    		 }
    When I set the timer, the data suppose to be fill on the listview but it have filled as empty items.

    Do you know why and how to fix this?
    Last edited by mark103; May 30th, 2011 at 07:57 AM.

  6. #6
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: List of errors when debug the application - please help!

    Quote Originally Posted by mark103 View Post
    Do you know why and how to fix this?
    Not really. I'd suggest to step through your code with the debugger and observe your data to find the spot where things begin to go wrong. Having narrowed down the bug location to that single small function makes that not much effort. The fact that you're getting empty items and not no items seems to indicate that there actually are regex matches.

    What is StrArr1 intended to be used for? You assign a value to it but then never use it. (You're not using r either but that seems to be unrelated to the problem.)
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  7. #7
    Join Date
    Aug 2007
    Posts
    448

    Re: List of errors when debug the application - please help!

    Okay, no worries. I think I got a different way to get this solve. Do you know how to do the autosearch for the textbox to search through the listview?

  8. #8
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: List of errors when debug the application - please help!

    I have not that much (well, to be honest, it's actually plain zero) experience with the ListView class. However, it looks like you intend to tie the selection of your ListView to a TextBox's TextCanged event. Though this certainly is possible in general it may raise some reaction time issues, based on what/how many data are stored there in the ListView. Basically I don't see an alternative to code that yourself.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured