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

  • Home
  • SEARCH
  • 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 9215199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:09:05+00:00 2026-06-18T02:09:05+00:00

I haven’t done hard core development in C++ since I made the switch to

  • 0

I haven’t done hard core development in C++ since I made the switch to C# about 5 years ago. I’m very familiar with using interfaces in C# and use them all the time. For example

public interface IMyInterface
{
   string SomeString { get; set; }
}

public class MyClass : IMyInterface
{
   public string SomeString { get; set; }
}

// This procedure is designed to operate off an interface, not a class.
void SomeProcedure(IMyInterface Param)
{
}

This is all great since you can implement lots of similar classes and pass them around, and no one is the wiser that you are actually using different classes. However, in C++ you can’t pass the interface around because you’ll get a compile error when it sees you trying to instantiate a class that does not have all its methods defined.

class IMyInterface
{
public:
   ...
   // This pure virtual function makes this class abstract.
   virtual void IMyInterface::PureVirtualFunction() = 0;
   ... 
}



class MyClass : public IMyInterface
{
public:
   ...
   void IMyInterface::PureVirtualFunction();
   ... 
}


// The problem with this is that you can't declare a function like this in
// C++ since IMyInterface is not instantiateable.
void SomeProcedure(IMyInterface Param)
{
}

So what is the proper way to get the feel of C# style interfaces in C++?

  • 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-18T02:09:06+00:00Added an answer on June 18, 2026 at 2:09 am

    Sure you can, but you need to pass references or pointers, not by value (well, pedantically speaking, pointers are passed by value as well):

    void SomeProcedure(IMyInterface& Param)
    

    I think it’s similar to C# in that regard, only that C# passes references to classes by default, whereas in C++ you explicitly have to say you want to pass it by reference.

    The pass by value will attempt to create a copy of the object, and an object of an abstract type (interface) doesn’t make sense, ergo the error.

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

Sidebar

Related Questions

I haven't done any iOS development since iOS 3, so my memory is a
Haven't done ASP.NET development since VS 2003, so I'd like to save some time
I haven't designed a website for about 3 years now, so I am quite
Haven't found anything useful about this on the internet. I'm using my Windows 7
Haven't done serious JavaScript since 90s, so looks like a couple of things changed.
I haven't programmed games for about 10 years (My last experience was DJGPP +
Haven't seen anything about it here but it seems to solve one of the
Haven't done as much of Javascript as I should have done. I am trying
Haven't touch javascript for 3 years. Just got a javascript project and wanted to
I haven't been able to find documentation that talk about how create.js.erb and destroy.js.erb

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.