Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7847497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:55:04+00:00 2026-06-02T17:55:04+00:00

I tried to extend a listbox by adding a couple functions. I get an

  • 0

I tried to extend a listbox by adding a couple functions. I get an error ( error C2144: syntax error : ‘Extended_ListBox’ should be preceded by ‘:’). Would anyone please teach me how to fix it? I went to the line which VC++ said there was the error, but I had no clue why the constructor had an error.

    using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Collections;
using namespace System::Collections::Generic;

#include <stdio.h>
#include <stdlib.h>
#using <mscorlib.dll>


public ref class Extended_ListBox: public ListBox{  

    public Extended_ListBox(array<String ^> ^ textLineArray, int counter){
        textLineArray_store = gcnew array<String ^>(counter);
        for (int i=0; i<counter; i++){
            this->Items->Add(textLineArray[i]);
            textLineArray_store[i] = textLineArray[i];
        }
        this->FormattingEnabled = true;
        this->Size = System::Drawing::Size(380, 225);
        this->TabIndex = 0;
        this->SelectedIndexChanged += gcnew System::EventHandler(this, &Extended_ListBox::listBox1_SelectedIndexChanged);
    }
    public Extended_ListBox(){
        this->FormattingEnabled = true;
        this->Size = System::Drawing::Size(380, 225);
        this->TabIndex = 0;
        this->SelectedIndexChanged += gcnew System::EventHandler(this, &Extended_ListBox::listBox1_SelectedIndexChanged);
    }
    private: System::Void listBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
                 int index=this->SelectedIndex;
                 tempstring = textLineArray_store[index];
         }  

private: array<String ^> ^ textLineArray_store;
private: String ^tempstring;
public: String ^GetSelectedString(){
            return tempstring;
        }
public: void ListBox_Update(array <String ^> ^ textLineArray, int counter){
        textLineArray_store = gcnew array<String ^>(counter);
        for (int i=0; i<counter; i++){
            this->Items->Add(textLineArray[i]);
            textLineArray_store[i] = textLineArray[i];
        }
        }
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:55:05+00:00Added an answer on June 2, 2026 at 5:55 pm

    In C++/CLI, you specify the access modifier (public, private, etc.) differently than in, say, C# or Java.

    Instead, you just write one line (note the colon, which is required):

    public:
    

    and all the following members are public. So insert that line before your constructors and remove the public keyword before the constructors. Like that:

    public ref class Extended_ListBox: public ListBox{  
    public:
        Extended_ListBox(array<String ^> ^ textLineArray, int counter){
            // constructor code
        }
    
        Extended_ListBox(){
            // default constructor code
        }
    
        // other public members 
        // ...
    
    private:
        // private members
        // ...
    }
    

    Similar to the members below the constructors in your current example, except that you don’t have to explicitly restate public: or private: if the next member has the same visibility.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting a weird error after I've tried to extend the MVC Membership provider in
I tried to extend the Connection class, like Ext.Ajax did to get a central
I tried to use object expression to extend the IDelegateEvent, but in fsi there
Is it possible to extend dynamically javascript function scope? I tried without success the
Tried a bunch of things but I can't get it to work consistently amid
Is it possible to extend the console object? I tried something like: Console.prototype.log =
Does anyone have suggestions for how to extend specifically Python 3 with C++? I've
I tried to extend a list and was puzzled by having the result return
I tried to to extend the code from this question for keeping records of
I've tried using merge and extend to combine arrays inside an Autocomplete ajax option

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.