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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:56:31+00:00 2026-05-27T22:56:31+00:00

What can I do to make this work: template<class C, class V, Test V::*>

  • 0

What can I do to make this work:

template<class C, class V, Test V::*>
class Test {
};

it gives me compiler error:

unknown type name 'Test'

It’s a self-referencing template for now, which doesn’t seem possible. What could possibly be done to make it work?

EDIT:

Here’s what I’d need this for. I want to implement a bi-directional (think parent-child) relationship schema with the least minimum coding effort.

template <class O, class T, Reference<T, O, Reference O::*> T::* opposite>
class Reference
{
    T **data;
    int count;
public:
    Reference(): data(new T*[N]), count(0) {}
    ~Reference() {delete[] data;}
    Reference &add(T *t) {
        handleOtherSide();
        return link(t);
    }
    // a lot of stuff to implement this
};

That’s the collection class. Here’s how it would be used:

class Partner
{
public:
    Reference<Partner, Address, &Address::partner> addresses;
};

class Address
{
public:
    Reference<Address, Partner, &Partner::addresses> partner;
};

My goal is to have everything necessary for Reference to work be supplied as template argument, so that there is no need to provide constructors for classes like Partner and Address (currently I supply the opposite member pointer as a constructor arg but this requires me to have explicit constructors for the participant classes). I would also need to pass in or calculate an “owner” pointer to the Reference class. I left this problem out here because I want to focus on the self-referencing template aspect.

The easiest way to think of this is boost::bimap. But the problem with bimap is that I don’t want the enclosing bimap but just the left and right part of it. bimap is also not feasible because it would lead to one single bimap managing all associations of a specific relationship. It would possibly hold a large number of objects slowing down operations on it.

  • 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-27T22:56:32+00:00Added an answer on May 27, 2026 at 10:56 pm

    The problem is, what I want to achieve is not possible in C++, at least not with templates and the amount of code and classes I am aiming at (read: single line of code per member). It starts with the compiler needing forward declarations and fully defined types, which is making by-value members and template arguments of such impossible (in case of cyclic dependencies). Then it is not possible to have a member pointer as a template arg when the class of that member is not yet fully defined. The root cause of all this is how the compiler works: it is single pass. And there is nothing I can do about that.

    The solution is to use by-reference members or an OO style base class or a boost::any style container to avoid the templates. With the latter 2 it might be possible to have by-value members.

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

Sidebar

Related Questions

How can I make this code work? class Meta @array = [:a,:b] def self.method_missing(name,
Can anybody please help me make this work? Donor-enumerate() doesn't work, gcc gives no
How can I make this work? switch(property.PropertyType){ case typeof(Boolean): //doStuff break; case typeof(String): //doOtherStuff
I can't for the life of me find a way to make this work.
How can I make something like this below work? <?PHP $_SESSION['signup_errors']['test1']; $_SESSION['signup_errors']['test2']; $_SESSION['signup_errors']['test3']; $_SESSION['signup_errors']['test4'];
In bash how can I make a construction like this to work: if (cp
How can i make an extension method that will work like this public static
I found this great Tablesorter plugin for jQuery but I can't make it work
This one seems to be a simple problem, but I can't make it work
I'm trying to make a simple Vector class (math) this way: template <int D,

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.