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 3967640
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:44:39+00:00 2026-05-20T03:44:39+00:00

Is it possible to set a member attribute in a generic way? I am

  • 0

Is it possible to set a member attribute in a “generic” way?
I am still new to c++ and just dived into templates, if this is the way to go?

The class i have to use has around 20 string members to be filled from informix database and i could loop through an array with the field(=attribute) names.

Let’s say i have a simple class

class Foo
{
  public:
    attr1
    attr2
  Foo() { };
  ~Foo();
}

and i could use it like that:

Foo foo;

string myattr = "attr1";
string myval = "val x1";
string myval = "val x2";

setattribute( foo, myattr, myval1 );   // pseudocode... possible somehow?
cout << foo.attr1;     // prints "val x1"

setattribute( foo, myattr, myval2 );   // pseudocode... possible somehow?
cout << foo.attr1;     // prints "val x2"

The method i call in the loop could look like this…

// its_ref : empty string reference
// row: ptr on the current db row = query result object
// colname:  the db column = attribute
// ki: the object 

void get_fd( ITString & its_ref, ITRow * row, ITString colname, ns4__SOAPKunde& ki ) {
        ITConversions *c;
        ITValue *v = row->Column( colname );
        v->QueryInterface(ITConversionsIID, (void **) &c);
        c->ConvertTo( its_ref );
        // here is the place i want to use it :
        setattribute( ki, colname, its_ref.Data() );
}
  • 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-20T03:44:39+00:00Added an answer on May 20, 2026 at 3:44 am

    You can use member data pointers. These can be of any type- e.g.

    struct x {
        int y;
        int z;
    };
    
    int main() {
        int x::* res = &x::y;
    }
    

    However, if you want to start accessing them by identifier at runtime, you will have to build your own system from scratch.

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

Sidebar

Related Questions

Possible Duplicate: Start thread with member function I have a small class: class Test
Is it possible to set the value behind a two-way binding directly, without knowing
Are class variables a good way to set the context for a class instance
Possible Duplicate: How to get the address of an overloaded member function? I have
Is it possible to have a static collection as a member of a hibernate
This question is kind of the next level of F# Set using custom class
Possible Duplicate: Class with indexer and property named “Item” Just came across something I've
I have a class: public class MyClass { public int code { set; get;
In gdb, is it possible to set a breakpoint on a member function called
Assuming I have a simple class that represents a staff member class Staff {

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.