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


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()

int main()
	Apple a;
	return 0;

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