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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:57:52+00:00 2026-05-13T05:57:52+00:00

I want to add a operator override to perform assignments /__set__s inline. Template :-

  • 0

I want to add a operator override to perform assignments/__set__s inline.

Template :-

class CBase {
    public :
        static void SetupVmeInterface(CVmeInterface *in);

    protected :
        static CVmeInterface *pVmeInterface;
};


template <class T> class TCVmeAccess : public CBase {
    public:
        TCVmeAccess(int address);

        T get()
        {
            unsigned long temp = pVmeInterface->ReadAddress(Address);
            T ret = *reinterpret_cast<T*>(&temp);
            return ret;
        };

        T *operator->();
        unsigned long asLong();

        bool set(T data)
        {
            unsigned long write_data = *reinterpret_cast<unsigned long*>(&data);
            return pVmeInterface->WriteAddress(Address, write_data);
        };

        // void operator->(T);
        void operator=(T data)
        { set(data); }

    private :
        int Address;
};

A struct that will be used in the template :-

typedef struct
{
    int a: 1; // 0
    int b: 1; // 1
    int c: 1; // 2
    int d: 1; // 3
    int NotUsed : 28; // 31-4
} _HVPSUControl;

Code body :-

TCVmeAccess<_HVPSUControl> HVPSUControl(constHVPSUControlBlock);
_HVPSUControl hvpsu = HVPSUControl.get(); // Yep, good, but not as nice as...
int a = HVPSUControl2.get().OperationalRequestPort; // yep, also good, but...
int b = HVPSUControl->a; // works, and is all go so far

HVPSUControl.set(hvpsu); // works, but need _HVPSUControl type
HVPSUControl = hvpsu;    // also works, as operator = is used, but still need type

// this line does not work!
// as the = assignment is redirected into a copy of the struct, not the template
HVPSUControl->a = 1; // this line

So, is there a way to get this line above to work?

Edit:
As in, I want “this line” to perform as a “set” as does in the template class.

Edit:
1. Assign a value directly in-line to a member of the struct that the template is formed
of.
2. Cause that assignment to go though a template accessor.

So that I dont have to do this on assignments :-

// HVPSUControl is predefined and used many times.
_HVPSUControl hvpsu;
hvpsu.a = 1;
HVPSUControl.set(hvpsu);

I want to do

HVPSUControl.a = 1; // or 
HVPSUControl->a = 1; // or ?

As gets work on line :

if (HVPSUControl->a)

  • 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-13T05:57:52+00:00Added an answer on May 13, 2026 at 5:57 am

    Instead of overwriting the “->” and the “=” operator, you could derive from the template struct.

    template <class T> class TCVmeAccess : public CBase, public T {
        public:
            TCVmeAccess(int address);
    
            T get();
            // T *operator->();
            unsigned long asLong();
    
            bool set(T);
            // void operator->(T);
            // void operator=(T);
    
        private :
            int Address;
    };
    
    HVPSUControl.a = 1; // and use this for setting a bitfield.
    

    Edit: If you want to use an custom assignment operator, you should declare it in HVPSUControl, or a even a base class of it, if you have more of this control-like structures.

    struct _HVPSUControl
    {
        int a: 1; // 0
        int b: 1; // 1
        int c: 1; // 2
        int d: 1; // 3
        int NotUsed : 28; // 31-4
        void operator = (int x);
    };
    

    or

    struct _HVPSUBase {
        void operator = (int x);
    }
    struct _HVPSUControl: public _HVPSUBase
    {
        int a: 1; // 0
        int b: 1; // 1
        int c: 1; // 2
        int d: 1; // 3
        int NotUsed : 28; // 31-4
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

interface IVehicle { void DoSth(); } class VW : IVehicle { public virtual void
I have a smart pointer class and I want to overload operator-> ; it's
In python 3, I want to do operator overloading in a class I've made.
I want add my custom sidebar next right column all page. Please check this
I have a website built with ASP.NET (3.5) and want add some level of
I have a list of string values that I want add to a hashtable
I have numbers in javascript from 01(int) to 09(int) and I want add 1(int)
I used RollingFileAppender. And I want add a blank line to the log when
I want to add a tab to a certain tab bar from inside the
I want to add some jQuery functionality to our sites where one piece of

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.