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

The Archive Base Latest Questions

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

PREFACE: I’m relatively inexperienced in C++ so this very well could be a Day

  • 0

PREFACE: I’m relatively inexperienced in C++ so this very well could be a Day 1 n00b question.

I’m working on something whose long term goal is to be portable across multiple operating systems. I have the following files:

Utilities.h

#include <string>

class Utilities
{
public:
    Utilities() { };
    virtual ~Utilities() { };

    virtual std::string ParseString(std::string const& RawString) = 0;
};

UtilitiesWin.h (for the Windows class/implementation)

#include <string>
#include "Utilities.h"

class UtilitiesWin : public Utilities
{
public:
    UtilitiesWin() { };
    virtual ~UtilitiesWin() { };

    virtual std::string ParseString(std::string const& RawString);
};

UtilitiesWin.cpp

#include <string>
#include "UtilitiesWin.h"

std::string UtilitiesWin::ParseString(std::string const& RawString)
{
    // Magic happens here!
    // I'll put in a line of code to make it seem valid
    return "";
}

So then elsewhere in my code I have this

#include <string>
#include "Utilities.h"

void SomeProgram::SomeMethod()
{
    Utilities *u = new Utilities();
    StringData = u->ParseString(StringData); // StringData defined elsewhere
}

The compiler (Visual Studio 2008) is dying on the instance declaration

c:\somepath\somecode.cpp(3) : error C2259: 'Utilities' : cannot instantiate abstract class
        due to following members:
        'std::string Utilities::ParseString(const std::string &)' : is abstract
        c:\somepath\utilities.h(9) : see declaration of 'Utilities::ParseString'

So in this case what I’m wanting to do is use the abstract class (Utilities) like an interface and have it know to go to the implemented version (UtilitiesWin).

Obviously I’m doing something wrong but I’m not sure what. It occurs to me as I’m writing this that there’s probably a crucial connection between the UtilitiesWin implementation of the Utilities abstract class that I’ve missed, but I’m not sure where. I mean, the following works

#include <string>
#include "UtilitiesWin.h"

void SomeProgram::SomeMethod()
{
    Utilities *u = new UtilitiesWin();
    StringData = u->ParseString(StringData); // StringData defined elsewhere
}

but it means I’d have to conditionally go through the different versions later (i.e., UtilitiesMac(), UtilitiesLinux(), etc.)

What have I missed here?

  • 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:18:52+00:00Added an answer on May 15, 2026 at 2:18 am
    Utilities *u = new Utilities();
    

    tells the compiler to make a new instance of the Utilities class; the fact that UtilitiesWin extends it isn’t necessarily known and doesn’t affect it. There could be lots of classes extending Utilities, but you told the compiler to make a new instance of Utilities, not those subclasses.

    It sounds like you want to use the factory pattern, which is to make a static method in Utilities that returns a Utilities* that points to a particular instance:

    static Utilities* Utilities::make(void) {return new UtilitiesWin();}
    

    At some point you’re going to have to instantiate a non-abstract subclass; there’s no way around specifying UtilitiesWin at that point

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

Sidebar

Related Questions

Preface: This question is about a project I am working on with a professor
Please let me preface this question with an apology. I am very new to
To preface this question, this is my first app and I have a very
To preface this question I should say I know very little about database efficiency
Let me preface this question by saying that I am relatively new to writing
Preface: This has become a quite a long post. While I'm not new to
Preface: This is a derivative question of the following questions: Best practice on passing
Preface: I'm not sure what resources are. I need this form (which is working
Preface: This question is a derivative of this answer , speaking specifically about NHibernate
I want to preface this question by stating that I am fairly new to

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.