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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:09:25+00:00 2026-05-26T08:09:25+00:00

The current specifications is: Given string data in the form of wide or narrow

  • 0

The current specifications is:

Given string data in the form of wide or narrow character arrays write the functionality for a class that provides statistics on the data and modifies the data.

The requirement is for it to be maintainable over the long term.

So my first approach is to require the raw char arrays be marshalled into strings prior, then just provide a template class:

template<class T>
class MyString
{
private:
    T _data;
public:
    MyString(T& input) { _data = input; }; 
    size_t doSomeWork() { //assume T is of type basic_string<...> and use iterators };

};


//Use
const char* data = "zyx";
string blahblah(data);
MyString<string> abc(blahblah);
abc.doSomeWork();

or static member functions:

class StringTools
{
public:
    static size_t doWork(const char*) {}
    static size_t doWork(const wchar_t*) {}
};

//used like so:
const char* data = "hallo kitty";
cout << StringTools::doWork(data);

or use a strategy pattern:

class MyString
{
protected:
    MyStringBase();
public:
    virtual ~MyStringBase();    
    virtual size_t doWork() = 0;
};

class MyStringCharArray : public MyString
{
protected:
    char* _data;
public:
    MyStringCharArray(const char* input) : MyString() { }
    virtual size_t doWork() {...};
};

//so it would be used like so
const char* blah = "blah";
MyString* str = new MyStringCharArray(blah);
cout << str->doWork();
delete str;

and then in the future if for some god forsaken reason i switch to BStr’s then it would only require that the first two lines of code be changed in addition to a new derived class being written.

I think that if i write a wrapper class as in 1 & 3 it becomes alot more heavy duty and any encapsulation is broken as i’d have to allow access to the underlying.

but if i create a class with only static functions then all it does is mimic a namespace which would be better served by some non-member non-friend functions encapsulated under a
“stringtools” namespace. But then i’d still be propagating the messyness of raw character arrays throughout the application and extra validation would have to be performed etc and the specification
asked explicitly for a class.

So what would be the cleanest and most maintainable approach to take?

rgds

  • 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-26T08:09:25+00:00Added an answer on May 26, 2026 at 8:09 am

    The best approach would be to do something like what stl algorithms do.

    Have a process algorithm that only takes the string char/wchart_t begin and end iterator. This way you algorithm will seamlessly work for all strings that can contiguous in memory.

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

Sidebar

Related Questions

Current, I've got a stored procedure that has a main goal of doing a
As a part of my current pet project, I have to write an program
Qt creator has option to promote one widget to customly created class that derives
Due to some protocol specifications for Quartz Composer, the string \0\0\0 has to precede
I remember in college taking a database class where we, the students, were given
For a given HTML form, is a user agent required to build the submit
Current situation: Ubuntu 8.04 server edition (live server) Postgresql 8.3.7 (from standard repositories) Postgis
Current Application Server Configuration: IIS 6.0 Windows 2003 Server Standard Edition SP2 .NET Framework
current code I've built function to do something over collection of jQuery elements: var
Current static source analysis tools for C# (or other .NET languages) usually operate on

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.