C++ - Functions are Public/Private by default?

Hi

I am just confused, when you declare a function in a class, is it public or private by default?

Pls help

By default, all declarations are private.

You really should make it clear if it is public, private or protected in your code by adding the correct statements. But yeah private unless stated otherwise.

There is a good guide to classes at cplusplus.com/doc/tutorial/classes/

Well let’s see:

#include <iostream>
using namespace std;

class Apple
{
	void sayhi()
	{
		cout<<"hi"<<endl;
	}
};

int main()
{
	Apple a;
	a.sayhi();
	
	return 0;
}

--output:--
error: 'void Apple::sayhi()' is private