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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:16:17+00:00 2026-06-09T02:16:17+00:00

There is a class Test: typedef enum { AA, BB } TType; template <typename

  • 0

There is a class Test:

typedef enum
{
    AA, BB
} TType;

template <typename T>
struct TVector
{
    typedef std::vector <T> Type;
};

template < typename T, const TType type >
class Test
{
private:
            typename TVector <T>::Type it; 
};

and its specialization with redefined operator = (there with no additional functionality):

template < typename T, const TType type >
class Test <T *, type> 
{
public:
    Test <T *, type > & operator = ( const Test <T*, type > &source ) {return *this;}

            template <TType type2>
    Test <T *, type > & operator = ( const Test <T*, type2 > &source ){return *this;}

            template <TType type2>
    Test <T *, type > * operator = ( const Test <T*, type2 > *source ) {return *this;}
};

I am trying to assign objects with different TType parameter each other, and this step works correctly.

int _tmain(int argc, _TCHAR* argv[])
{
Test <double *, AA> a1;
Test <double *, BB> b1;

a1=b1;  //Correct

Test <double *, AA> *a2;
Test <double *, BB> *b2;

a2 = b2;  //Error

return 0;
}

But the same step with pointers does not work, see the error code:

Error   1   error C2440: '=' : cannot convert from 'Test<T,type> *' to 'Test<T,type> *' 49

Is it possible to assign pointers with different TType parameter each other (how?) or not?

Updated question:

And what about assignment between pointers and objects?

a2 = &b1;  //Error
*a2 = b1;  //Unitialized memory

Could I ask for a code sample?
Thanks for your help.

  • 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-06-09T02:16:19+00:00Added an answer on June 9, 2026 at 2:16 am

    The second example does not work because you are not assigning to the object, you are assigning to a pointer. It’s the same reason that this does not work:

    int * a;
    float * b;
    
    b = a;
    

    Even though a float can be assigned from an int, a pointer to float cannot be assigned from a pointer to int.

    Try *a2 = b2 or *a2 = *b2 instead — your operators should catch both of those.

    Note also that this implementation appears to be wrong:

    template <TType type2>
    Test <T *, type > * operator = ( const Test <T*, type2 > *source )
    {
        return *this;
    }
    

    The this implicit variable is already a pointer type, so you need to return this, not return *this. I would suggest eliminating this overload of the assignment operator completely, since it is bound to be more confusing than it will be useful.

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

Sidebar

Related Questions

Test.h #ifndef TEST_H #define TEST_H #include <memory> template <class Type> bool operator==(const std::weak_ptr<Type>& wp1,
In code: template<class T> struct is_builtin { enum {value = 0}; }; template<> struct
If there are several methods in the test class, I found that the order
In my webpage, there's a div with a class named Test . How can
there are some code as this: <div class=test> <div class=upsell-tags> <?php echo $this->getChildHtml('product_additional_data') ?>
How do I inherit from a virtual template class, in this code: // test.h
Consider a simple case public class Test { public String myString; } Is there
My Question is: I have a test.java class which is the main class. There
In my code, I need to test if a type given to a template
There are 2 template classes A and B having 2 private members a1, a2

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.