Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "class :" mean in C++?

Tags:

c++

class

colon

I've never seen it before. I thought it was a typo for "::sample", but when I saw it actually compiles I was very confused. Can anyone help me find out please? I don't think it's a goto label.

void f() {   class: sample {     // there were some members declared here   } x; } 
like image 405
Johannes Schaub - litb Avatar asked Jan 17 '11 11:01

Johannes Schaub - litb


People also ask

Why do we use classes in C?

C mostly uses functional/structural programming instead of implementing Object Oriented Programming as in languages like C++ , Java , Python etc. which use classes .

What does class :: mean in C++?

The :: (scope resolution) operator is used to qualify hidden names so that you can still use them. You can use the unary scope operator if a namespace scope or global scope name is hidden by an explicit declaration of the same name in a block or class.

What is class and object in C?

The main purpose of Objective-C programming language is to add object orientation to the C programming language and classes are the central feature of Objective-C that support object-oriented programming and are often called user-defined types.

What does class mean in code?

In object-oriented programming , a class is a template definition of the method s and variable s in a particular kind of object . Thus, an object is a specific instance of a class; it contains real values instead of variables. The class is one of the defining ideas of object-oriented programming.


1 Answers

It is an unnamed class, and the colon means it inherits privately from sample. See it like

class Foo : private sample {     // ... };  Foo x; 
like image 136
Alexandre C. Avatar answered Sep 23 '22 21:09

Alexandre C.