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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:28:13+00:00 2026-06-10T22:28:13+00:00

I have a set of classes that are used to prepare data for serialization.

  • 0

I have a set of classes that are used to prepare data for serialization. All of them are derived from the base class cBase, which doesn’t hold anything related to the question.

Among the derived classes there are:

class cValue: public cBase
{
public:
    cValue(){}
    template< class T > void set( const T & value ){ data_ = value; }

protected:
    QVariant data_;
};

This is the class for holding simple values like a string or a number. And here is a class to represent an object (basically something that can hold “name-value” pairs:

class cObject: public cBase
{
public:
    cObject(){}

    void addAttribure( const QString & name, cBase * value )
    {
        if( attributes_.contains( name ) )
            delete attributes_[name];
        attributes_[name] = value;
    }

    template< class T > void addAttribure( const QString & name, const T & value )
    {
        cValue * tmp = new cValue();
        tmp->set( value );
        addAttribure( name, tmp );
    }
protected:
    QMap< QString, cBase * > attributes_;
};

The purpose of this is to be able to add attributes both with already-created objects: addAttribute(someName, someObject); and with raw values: addAttribute("name", 42);

Now, as it is, this code compiles. However, if I try to create an object like this:

cValue *tmp = new cValue();
tmp->set( 42 );
cObject obj;
obj.addAttribure("The Answer", tmp);

I’m getting the following error:

/usr/include/qt4/QtCore/qvariant.h:429:12: error: 'QVariant::QVariant(void*)' is private
../../source/private/../include/MyClasses.h:36:51: error: within this context

The error appears on the line where cValue‘s set() function is declared.
Now if I remove the templated version of addAttribute(), and place the exact same code from that function into my main:

cObject obj;
cValue * tmp = new cValue();
tmp->set( 42 );
obj.addAttribure( "The Answer", tmp );

it works fine. I figure it has something to do with the fact that both addAttribute() and set() functions are templated, but I fail to understand how to fix this issue, or at least how to make a workaround.

Note: if possible, I would like to not make the classes themselves templated, only the functions.

  • 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-10T22:28:15+00:00Added an answer on June 10, 2026 at 10:28 pm

    The problem is that you’re expecting the compiler to call addAttribure(const QString& name, cBase* value) when using cValue, because cValue is derived from cBase. But as they are not an exact match, the compiler calls addAttribure<cValue*>(const QString& name, const cValue* value) instead.

    That’s why (as noted in your comment) calling addAttribure(name, static_cast<cBase*>(tmp)) worked.

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

Sidebar

Related Questions

Present Scenario : I have a set of classes that all take a common
I have a set of classes that are used multiple times on a page
I have a parent class in rails that inherits from ActiveRecord::Base. I'm trying to
I have a set of ~5 ActionScript 3 classes that are currently used within
I'm using ASP.NET MVC RC2. I have a set of classes that were auto-generated
I have a project with a set of classes that are responsible for their
I have written a set of classes and interfaces that are implemented in Moose
I have two classes set up as follows: class Point { protected: double coords[3];
I have two classes: public class MultilingualString { public int Id { get; set;
I have an existing set of classes that use the [Serializable] attribute. I need

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.