interfaces in c++

#include <iostream>
#include  <string>
//Pure virtual function or inteface allows us to define a function in a base class that doesn't have an implementation or definition in the base class and force sub classes to implement that function
//Pure virtual function is also called an interface in other languages
class Entity {
public:
	//virtual std::string GetName() { return "Entity"; }//This is a function that is just virtual .Overriding this function in sub class is optional we can instantiate subcllass without overriding  or implementing this function
	
	//Below is an example a Pure Virtual Function
	//It is an unimplemented function ant it forces the  sub class to implement it and define it
	//You will not be able to instantiate sub class without implementing or defining the function in sub class
	virtual std::string GetName() = 0; 
  //the pure virtual function must have virtual written at the beginning and =0 at the end
 //This function cannot contain any definition in base class,it is just a declaration
};
class Player :public Entity {
	std::string m_name;

public:
	Player(const std::string& name)
		:m_name(name)
	{};
	void Print() { std::cout << "This is Sub class" << std::endl; };
	std::string GetName()override { return m_name; };//Pure virtual functions is implemented here in this sub class
};

int main()
{
	//Entity a;//We can't do this because class Entity contains function that is unimplemented
	Player x("Jacob");//This will work because we have implemented or defined the function in this sub class
	std::cin.get();
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
c++ interface means interface in c++ implement creating interfaces cpp c++ interface and how to use it what is interface in cpp how to create a interface in c++ c++ implement an interface creating an interface c++ c++ interface method cpp define interface how to declare interface in c++ c++ creating an interface interface function c++ interface c++ keyword C++ interface class implementation What are Interfaces and how to implement interfaces? CPP create interface class c++ c++ interfaces example interface in c++\ using interface classes c++ c++ interface design c++ variable interface c++ using an interface an interface class in C++ how to make an interface c++ interface A{} in cpp cpp interface example c++ example interface class interface equivalent in c++ c++ equivalent of interface how to do user interface in c++ interface class in c++ what is a c++ interface interface classes c++ user interface with c++ interface and implementation in c++ interface from interface c++ example of interfaces c++ concept of interfaces in c++ c++ what is an interface implements interface in c++ interface inherting interface C++ c++ what the best way to write an interface C++ implement interface how to interface c++ c++ interface programming what would be interface in c++ crreating interface classes c++ what is an interface class in c++ is a double abstract in c++ cpp abstract class c++ abstract class example abstract c++ interface implement c++ cpp make interface abstract claass c++ which classes can use c++ interfaces when to use interface cpp what is an interface in c++ what is an abstract class c++ how to create an interface in c++ interface and abstraction c++ interface i c++ how to implement abstract class library in c++ how to implement abstract class in c++ is there interface in c++ how to create interface in cpp use of abstract class in c++ what is an interface c++ c++ common interface class interfaces cpp what is interface in c++ how do you implement abstract classes in c++ example of interface in c++ interfaces in c++ example abstract cpp abstract classes in c++ c++ class interface class interface c++ c++ Provide the class declaration (interface) abstract class c++ interface class Interface and Implementation c++ interface in c++ example implementing methods of abstact classes c++ interface in c++ gfg interface vs abstract class in c++ how to write interface in c++ interface c++ example interface function in c++ c++ interface class abstract in c++ interface class cpp abstract class cpp Interface in c++ always describe c++ function interface interface class c++ c++ filed in abstract and method in interface c++ abstract class vs interface cpp interface create interface C++ abstract classes c++ interface vs abstract class cpp c++ abstract interface of class in c++ Interfaces C++ what is inteface in cpp interfaces in cpp abstract class in c++ example interface cpp interface c++ cpp interfaces c++ interface tutorial c++ abstract classes c++ interfaces abstract class c++ c++ abstract class abstract class in c++ create interface in c++ c++ interface example c++ interface interface in cpp what are interfaces in c++ interface in c++ interfaces in c++
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source