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

The Archive Base Latest Questions

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

My situation is a follows: There is some class MyList that will probably get

  • 0

My situation is a follows: There is some class MyList that will probably get a specific implemenation later on. For now, behavior like std::vector is fine.

However, I really need an easy way to call some kind of asString() / toString() method on it, because I’ll need it in test assertions, debug output and so on. The only options I see are:

  1. Public inheritence. I’ll never delete such a list through a base-pointer, since there should never be any base pointers. If I do, there will be no pointer members, anyway. However, rule of thumb still states: Don’t inherit from stl containers.

  2. Some kind of “global” (actually in a namespace, of course) method that takes an instance of MyList as argument and does the asString() magic for me. In that case, MyList could be a simple typedef for std::vector.

I like neither of those options too much. Is there something else I failed to think of? Or if not – which way should I prefer?

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

    what is wrong about the second approach? that is by far the easiest and also pretty elegant.-
    Imagine the alternative of wrapping the vector. that would cause you alot of extra work and glue code that is error prone! I’d go with the function approach for sure!

    edit: btw, i almost exclusively use free functions(sometimes static members) for conversions. Imagine you have a load of types that somehow need to be convertible to string. Having the toString() functions as free functions and not as members does not give you the headache you are heaving right now since you can basically simply overload the function as much as you want and don’t have to touch any existing classes (or maybe classes that you don’t even have source access to).

    Then you can have a function like:

    template<class T>
    void printDebugInfo(const T & _obj)
    {
       std::cout<<toString(_obj)<<std::endl;
    }
    

    and you wont have the constraints you are experiencing.

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

Sidebar

Related Questions

I'm making a DLL (and probably a Linux port at some later date) in
Question is as follows: There are 2 related tables (am giving some sample values
The situation is as follows: I have a ViewModel that has a property that's
Recently I was repairing someone's code. There was a big class that would not
The situation is as follows. public interface IFoo { } public abstract class FooBase
The situation is as follows: I've got 2 models: 'Action' and 'User'. These models
I have a situation as follows <body> Test<br /> test<br /> test1<br /> </body>
Our situation is as follows, but I'm curious about this problem in any situation.
The situation is as follows: A series of remote workstations collect field data and
My situation is as follows: I'm working on an implementation of BlackJack. I've got

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.