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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:16:21+00:00 2026-05-15T02:16:21+00:00

let’s say I want my users to use only one class, say SpecialData. Now,

  • 0

let’s say I want my users to use only one class, say SpecialData.
Now, this data class would have many methods, and depending on the type of data, the methods do different things, internally, but return externally similar results. Therefore my wanting to have one “public” class and other “private”, child classes that would change the behavior of methods, etc…

It would be amazingly more simple for some types of data that need to be built to do something like this:

SpecialData& sm = SpecialData::new_supermatrix();

and new_supermatrix() would return a SuperMatrix instance, which inherits from most behaviors of SpecialData.

my header:

static SpecialData& new_supermatrix();

my cpp:

SpecialData& SpecialData::new_supermatrix()(){
  return SuperMatrix(MATRIX_DEFAULT_MAGNITUDE,1000,1239,FLOAT32,etc...);
}

The problem is, I get this error, which is probably logical due to the circumstances:

invalid initialization of non-const reference of type ‘SpecialData&’ from a temporary of type ‘SpecialData’

So, any ideas?

  • 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-15T02:16:22+00:00Added an answer on May 15, 2026 at 2:16 am

    Well, you’ve got three choices:

    a) You want to have only one instance of SuperMatrix anyway. Then go for the static function member route as has already been suggested.

    b) You want to create multiple instances. Then you have to return a pointer instead of references and create the objects with with new (i.e. return new SuperMatrix(...).

    c) As an alternative to option b, you can also return merely an object, i.e.

    SpecialData SpecialData::new_supermatrix()(){
    return SuperMatrix(MATRIX_DEFAULT_MAGNITUDE,1000,1239,FLOAT32,etc...);
    }
    

    However, this requires a (deep-)copy operator (the default one won’t suffice more often than not), and it means that the object is created on the stack, then copied and that copy is being returned. The good thing is, this won’t leak memory if you don’t actually receive the result into a variable. The bad thing is, if the object is very large, this can be very memory- and time-consuming.

    Whatever you are going to do with it, these solutions are mutually exclusive, both technically and logically. 😉

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

Sidebar

Related Questions

Let's say I have a class like this: public class Person { private String
Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have a drive such as C:\ , and I want to
Let's say I have a link in a table like: <td class=ms-vb width=100%> <a
Let's say I have this: public DefaultListModel model = new DefaultListModel(); how do i
Let's say I have two files.. I want to compare them side-by-side and see
Let's say I have a table that looks something like this: ------------------------------- id|column2|column3 |column4
let's say i have three tables, each one relates to another, when i need
Let's say I have a JS in one file that creates a Viewport :

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.