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

  • Home
  • SEARCH
  • 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 4620022
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:30:13+00:00 2026-05-22T02:30:13+00:00

I have an interface that has ~16 input field boxes. They are all declared

  • 0

I have an interface that has ~16 input field boxes. They are all declared as public pointers within a class, initialized, etc. However, as my code has grown more and more with private functions doing database committals, error checking, temporary storage routines, etc it has become very painful if a field has to get removed or a new one added I must delve into all these private functions and explicitly remove/add the field; and always with regard to the field ordering.

There has to be a simpler way!

This is my idea and am hoping anyone can shoot it down or build upon it:

My thought is to store pointers to all the input fields in a array of pointers and then all these private helper functions walk the array; however some of these private functions are static some are non-static; thus some more pointer magic is required, or should I have two of these array-of-pointer functions: one for static functions to use and one for non-static functions to use?

To further complicate things, the method invoked upon the widgets varies depending on what the private function is doing… Some may call “->value(foo)” some may call “->location(1),->location(2),” incrementing in order of the widgets. Is there a way to pass the method invoked and the parameters to be passed to this new helper function containing the array of input field pointers?

Food for thought:
Maybe I’m trying to get too fancy by saving myself the burden of scrolling all around my code whenever I need to make a change? Maybe this will add too much overhead with all the extra pointer indirection? Is it better to suffer?

Thanks, any help is appreciated. If some code examples are really required I can churn out some.

Code Example (this won’t compile and is typed freehand as an example)

class Foo
{
public:
   InputBox * in1;
   InputBox * in2;
   InputBox * in3;
   ExternalDataSource * exds; // Pretend this object you can retrieve values out of
private:
   static void clearFieldsFunc1(void * v); // callback bound to a button
   static void loadFieldFunc2(void * v);  // callback bound to a button
   void printFieldsFunc3(); // not a callback, just called from various functions
}

Foo::Foo()
{
   in1= new InputBox (0,0,10,10);  // Box x,y,w,h
   in2= new InputBox (15,0,10,10);
   in3= new InputBox (30,0,10,10);
   exds = new ExernalDataSource("US Intelligence Agency");
}

// Clears the fields
void Foo::clearFieldsFunc1(void * v)
{
   Foo * fptr = ((Foo*)v);
   fptr->in1->clear();
   fptr->in2->clear();
   fptr->in3->clear();
}

// Loads the fields
void Foo::loadFieldFunc2(void * v)
{
   Foo * fptr = ((Foo*)v);
   fptr->in1->value(fptr->exds->getValue(1));
   fptr->in2->value(fptr->exds->getValue(2));
   fptr->in3->value(fptr->exds->getValue(3));
}

// Prints the fields
void Foo::printFieldsFunc3()
{
   printf("%s\n",this->in1->value());
   printf("%s\n",this->in2->value());
   printf("%s\n",this->in3->value());
}
  • 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-05-22T02:30:14+00:00Added an answer on May 22, 2026 at 2:30 am

    You could possible add a container of InputBox as a member to Foo and iterate it to make life simpler.

    #include <vector>
    
        class Foo
        {
        private:
           static void clearFieldsFunc1(void * v); // callback bound to a button
           static void loadFieldFunc2(void * v);  // callback bound to a button
           void printFieldsFunc3(); // not a callback, just called from various functions
    
           std::vector<InputBox> m_inputBoxes;
           typedef std::vector<InputBox>::iterator InputItr;
        };
    
        Foo::Foo()
        {
           m_inputBoxes.push_back(InputBox(0, 0, 10, 10));
           m_inputBoxes.push_back(InputBox(15, 0, 10, 10));
           m_inputBoxes.push_back(InputBox(30, 0, 10, 10));
        }
    
        // Clears the fields
        void Foo::clearFieldsFunc1(void * v)
        {
           for(InputItr itr(m_inputBoxes.begin()); itr != m_inputBoxes.end(); ++itr)
               itr->clear(); // calls clear for each InputBox
        }
    
        // etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that (amongst other things) has a command line interface that
I have an interface -- EventHandler -- that declares several methods. public interface EventHandler
I have a ViewModel class that implements the IDataErrorInfo Interface . In each property's
I'm working with java. I have an interface that has an annotated method in
I have been working on a project that has 2 interfaces - windows forms
I have an interface that I have defined in C++ which now needs to
I have a interface that defines some methods with attributes. These attributes need to
I have an interface that defines some methods I would like certain classes to
I have an interface that needs to react to long key presses. That means
Lets say you have interface definition. That interface can be Operation . Then you

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.