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 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

I have a class: public class MyClass { public int code { set; get;
Given this class class Foo { // Want to find _bar with reflection [SomeAttribute]
I have this code that does not compile anymore since I am on last
In a class, I've got a trace method that looks like this: [System.Diagnostics.ConditionalAttribute(Trace)] private
Suppose I have the following (trivially simple) base class: public class Simple { public
Is it possible to generate a property with a public getter and a protected
I'm attempting to deserialize a custom class via the XmlSerializer and having a few
Is it possible to remove attributes from inherited properties? I thought that by using
Using a code activity (i.e. activity built out of C#) we can add category
I'm trying to obtain a list of all Machines that are members of a

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.