Class++ | Classes and OOP made easy and powerful with Access Specifiers, function overloading and more!

I’ve found many really usefull resources on dev forum that I use to make the developement of my projects faster. But that one might be one of the greatest, this is just paradise for I and probably much others that knows C++.Thank you for this

1 Like

Any ETA on when this will be available for the new solver? Really looking forward to using this on my projects but i’m unsure if I should start with the current version or just wait for 2.0.

Also off-topic but I really liked the docs website and i’m using it as reference for my own, so huge props for that.
1 Like

2.0.0 will take a while to get out, due to the new solver still being unstable. It is becoming more and more usable every week, but not there yet.

A beta version is coming out in the next week with certain features, though I’d still recommend you go with 1.2.1 for now. It’s the most stable and finished version.

Also, thanks. Docs will recieve an update with 2.0.0, a new theme with some rewording to be more consistent.

1 Like

Good stuff, especially for someone like me who hates looking at Metatables.

1 Like

Will Beta Version contain the types feature (at least a somewhat working version)? Thanks :pray:

hello, im having trouble with the Friend Access Specifier.
i try to make class1 access class2’s private members.
i end up getting “{Class++}: Cannot call function directly.” error instead.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClassPP = require(ReplicatedStorage["Class++"])

local class = ClassPP.class

local Car = class "Car" {
	Public = {
		Brand = "Lamborghini",
		ask_for_license_plate = function(self, object:any)
			print(object.License_Plate)
		end
	},
	Private = {
		License_Plate = "XXXX",
	},
	Friend = {
		"Other Car"
	},
}

local OtherCar = class "Other Car" {
	Public = {
		Brand = "Ferrari",
		ask_for_license_plate = function(self, object:any)
			print(object.License_Plate)
		end
	},
	Private = {
		License_Plate = "XXXX",
	},
	Friend = {
		"Car"
	},

}

local newCar = Car.new()
local newOtherCar = OtherCar.new()

newCar:ask_for_license_plate(newOtherCar)
newOtherCar:ask_for_license_plate(newCar)

Yeah, unfortunately this is a bug. I’ve fixed it and will be including it to the next version of Class++.
For now, you can work around this issue by making the license plate function a friend function instead.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClassPP = require(ReplicatedStorage["Class++"])

local class = ClassPP.class

local function ask_for_license_plate(object: any)
	print(object.License_Plate)
end

local Car = class "Car" {
	Public = {
		Brand = "Lamborghini"
	},
	Private = {
		License_Plate = "XXXX",
	},
	Friend = {
		ask_for_license_plate
	},
}

local OtherCar = class "Other Car" {
	Public = {
		Brand = "Ferrari"
	},
	Private = {
		License_Plate = "XXXX",
	},
	Friend = {
		ask_for_license_plate
	},

}

local newCar = Car.new()
local newOtherCar = OtherCar.new()

ask_for_license_plate(newOtherCar)
ask_for_license_plate(newCar)
1 Like

The first beta version will contain automatic type creation depending on the classData.
This means that you will be able to get type-checking easily for classes within classes, or objects within objects.

2 Likes

Release Version 0.0.1 (New Type Solver Beta)


Hello everyone! This update is about the new re-write of Class++ for the new type solver. This is one of the many updates that will come, so stay tuned.

  • The module has been re-written from the ground up.
    • Main module has been re-written to support the new type solver, and allow for a better experience using Class++.
    • The main API Surface is the same, however certain method behaviors have changed.
    • Replaced the Error API with a much better and expandable Log API.
    • Updated the Type API to make it more compatible and stable (it can even be used as a replacement for built-in type methods), however, method names are changed.
  • Updated Inheritance (Part 1)
    • Removed class.extends method and instead merged the functionality with the class method of the main API.
    • Class++ now supports multi-inheritance.
    • Constructor calling mechanism has been revamped to fix bugs related to parent class constructors not being called properly.
    • Inherited classes now have proper type-checking with the new type solver, this also includes objects.
  • Replacing the Error API with Log API
    • To make debugging easier, Class++ error messages are now more consistent in style and easier to read, and they will now provide links (in Studio) to find more information about the error.
    • Certain error messages now provide more information to make debugging easier.
  • Type API is now more stable and compatible
    • The old Type.typeof() and Type.typeofClass() methods have been replaced with Type.type() and Type.typeof() methods that are more compatible with Luau’s built in type() and typeof() functions. You can even replace the built-in methods with the new Type API methods, and they will still work! (Type API provides type support for class and object userdatas.)
  • Major bug fixes
    • Fixed Friend access specifier not using the class references properly to allow other classes access to Private and Protected members.
    • Fixed overloaded functions not being able to access Private and Protected members of their class.
    • Fixed bugs related to being able to set a class member to nil.
    • Fixed bugs related to inheritance.

:warning: Notes:

  • Because the new type solver is still in beta, certain type-related features may stop working or cause bugs. And even though the new solver is far more capable than the old one, it’s still limited in certain places. That’s why if you encounter an issue, please make a bug report.
    (Due to this, it is not recommended to use this version in production.)
  • This release only contains a certain part of the announced/planned features from the discussions page. Rest of the planned features and more will come soon.

:exclamation: Since this is a beta that relies heavily on the New Type Solver, you must enable it from Beta Features in order to use this version of Class++.
And due to this version being a beta, the download is only on the github page.

4 Likes

Hot, may look into playing around with it soon ty!

1 Like

how do we inherit/extend in this version?

1 Like

I’ll be updating the documentation soon, but you can check out the discussions page on GitHub to learn more about the full changes to the Inheritation.

Right now, you can create an inherited class by using the class method:

local firstClass = class "Test" {}
local secondClass = class "Second" (firstClass, nil) {
   Public = {
   
   }
}
2 Likes

Hi, the github pages api reference seems to be gone and I can’t figure out how to do certain things (like set private fields) when the class is constructed :frowning:

Nvm you do it via the constructor field, but I couldn’t find that through a quick skim :frowning: You should fix da post

Oops, sorry. I did a major update to the documentation, it’s now version based due to the new 2.0 update being a major update that changes a lot of things about the API. The link should work now, thanks for the info.

1 Like

Hello! The documentation has went through an overhaul, which brings in a new style and new sections.

  • The documentation style has been changed to adopt a more modern style, meanwhile not reducing information quality.

  • The documentation elements are now more compatible with light-mode.

  • The documentation info has been updated to contain Class++ 2.0’s features. (e.g Inheritance)

  • An Error section has been added to the API-Reference that contains info about all the possible errors that Class++ may print into the output.

And many more! Check it out, and make sure to give feedback!

(Note: Certain sections have not been updated yet, such as Type, and may contain outdated information. They will be updated to contain up-to-date info, and certain other sections will be re-worded to sound more clear.)

https://tenebrisnoctua.github.io/ClassPP/2.0/

1 Like

Another update to the documentation:

  • Certain sections have been reworded to sound more clear.
  • Type section now contains up-to-date info.
  • Added a notification banner to the top that indicates 2.0 is still in beta.
  • Updated certain icons.
  • Light and Dark themes are now more consistent.

To access the new documentation, you can select “2.0” in the version selector at the top.

Also, Class++ now has a new icon! It should look much better and modern.

1 Like

hey so I was wondering. how would I make an enemy using this? with all I need to do is call it and it would work.

Quite similar on how you would do it normally with OOP. Except it would be simpler as you don’t have to work with metatables.

Oh I am very unfamiliar with using oop, but I figured it out though!

1 Like

Release Version 0.1.0 (New Type Solver Beta)


  • Updated Inheritance (Part 2)
    • Added super().
    • Changed the Protected Access Specifier behavior to allow for a better overwriting system. (Similar to C++)
  • Type.type and Type.typeof functions have been updated to better support objects.
  • class.new now reflects the parameter types of the defined constructor function in the classData table.
  • The object will now have auto-completion for certain default methods.
  • Removed unnecessary message templates.
  • Fixed bugs allowing you to re-define members in different access specifiers.
  • Improved performance.
  • Updated the documentation.

:warning: Notes:

  • Because the new type solver is still in beta, certain type-related features may stop working or cause bugs. And even though the new solver is far more capable than the old one, it’s still limited in certain places. That’s why if you encounter an issue, please make a bug report.
    (Due to this, it is not recommended to use this version in production.)
  • This release only contains a certain part of the announced/planned features from the discussions page. Rest of the planned features and more will come soon.

:exclamation: Since this is a beta that relies heavily on the New Type Solver, you must enable it from Beta Features in order to use this version of Class++.
And due to this version being a beta, the download is only on the github page.

1 Like