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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:22:46+00:00 2026-06-02T15:22:46+00:00

I asked a while ago how to use virtual classes in c++ , and

  • 0

I asked a while ago how to use virtual classes in c++, and to my dismay i learned that you can’t. But one user,(namely “Emilio Garavaglia” thanks a bunch), posted a way to get something similar to virtual classes, just with some extra code. however, i’m having some trouble getting what i’m doing to compile. here’s the code:

global_defs.h

#define Interface class

#define abstract_class class

#define implements : public 

I_Graphics.h

#ifndef I_GRAPHICS_H
#define I_GRAPHICS_H

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

Interface I_Graphics
{
public:
    virtual ~I_Graphics() {};

    virtual void Initialize() = 0;
    virtual void Frame() = 0;
    virtual void Shutdown() = 0;

    class I_Model;

    virtual I_Model * CreateModel() = 0;

};

Interface I_Graphics::I_Model
{
public:
    virtual ~I_Model() {}

    virtual void Initialize(std::string const & filename, std::string const & textureFilename) = 0;
    virtual void * GetVertexBuffer() = 0;
    virtual void * GetIndexBuffer() = 0;
};


#endif

Graphics.h

#ifndef GRAPHICS_H
#define GRAPHICS_H

#include "global_defs.h"

#include <map>
#include <string>
#include <memory>
#include "I_Graphics.h"

class Graphics implements I_Graphics
{
public:
    Graphics();
    ~Graphics();

    void Initialize();
    void Frame();
    void Shutdown();

    class Model;

    I_Model * CreateModel() {return new Model;}   // <--- compile error here

private:
    std::map <std::string, I_Model *> m_ModelList;
};

class Graphics::Model implements I_Graphics::I_Model
{
public:
    Model();
    ~Model();

    void Initialize(std::string filename, std::string textureFilename);
    void * GetVertexBuffer();
    void * GetIndexBuffer();
};

#endif

Graphics.cpp
nothing going here, havn’t really started working on the hard part yet, just trying to get the model instantiation to work.

#include "Graphics.h"

Graphics::Graphics()
{

}

Graphics::~Graphics()
{
}

void Graphics::Initialize()
{

}

void Graphics::Frame()
{

}

void Graphics::Shutdown()
{

}

Graphics::Model::Model()
{

}

Graphics::Model::~Model()
{
}

void Graphics::Model::Initialize(std::string filename, std::string textureFilename)
{


}

void * Graphics::Model::GetVertexBuffer()
{
    return NULL;
}

void * Graphics::Model::GetIndexBuffer()
{
    return NULL;
}

so, as the little comment says, i get an error there saying:

error C2512: 'Graphics::Model' : no appropriate default constructor available

when there obviously is a constructor for it in graphics.cpp . Can someone please explain what the compiler is complaining about here?

EDIT:
not sure if it means anything, but when mousing over the little red squiggle in MSVC, it says, “object of abstract class type Graphics::Model is not allowed” . …but it doesn’t have any pure virtual members, so it’s not abstract right?

EDIT:
On the suggestion of Castilho, i declare CreateModel in graphics.h like before, but then defined it in graphics.cpp, and it yielded a much more specific error, but i still don’t understand why.

error C2259: 'Graphics::Model' : cannot instantiate abstract class
1> due to following members:
1> 'void I_Graphics::I_Model::Initialize(const std::string &,const std::string &)' : is abstract
1> i_graphics.h(28) : see declaration of 'I_Graphics::I_Model::Initialize'

  • 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-02T15:22:47+00:00Added an answer on June 2, 2026 at 3:22 pm

    You’re using the Model class before it is defined. Define the function CreateModel in a separate CPP and it may work.

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

Sidebar

Related Questions

While I realize that this question has been asked once or twice ago but
UPDATE 10/19/2010 I know I asked this question a while ago, but the workarounds
Okay so I know I asked a similar question a while ago, but this
This was asked quite a while ago in SO but there isn't a definitive
Quite a while ago, someone asked how you can make Visual Studio's debugger play
I asked this question a while ago and got an answer that I thought
I have question quite much related to this one I asked a while ago
I asked a similar question a while ago Error Creating Debug Information - Code
This question was asked quite some time ago, and while it covers possible solutions
While I'm perfectly willing to believe that this has been asked elsewhere, I haven't

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.