anagha
14
Q:

class in c++

class Object {
public:
	int var;
	void setVar(int n) {
		var = n;
	}
	int getNum() {
		return var;
	}
};

int main() {
	Object obj;
	obj.setVar(13);
	std::cout << obj.getNum() << std::endl;
	return 0;
}
3
class Personnage
{
    
}; // N'oubliez pas le point-virgule à la fin !
1
// C++ program to demonstrate  
// accessing of data members  
  
#include <bits/stdc++.h> 
using namespace std; 
class Geeks 
{ 
    // Access specifier 
    public: 
  
    // Data Members 
    string geekname; 
  
    // Member Functions() 
    void printname() 
    { 
       cout << "Geekname is: " << geekname; 
    } 
}; 
  
int main() { 
  
    // Declare an object of class geeks 
    Geeks obj1; 
  
    // accessing data member 
    obj1.geekname = "Abhi"; 
  
    // accessing member function 
    obj1.printname(); 
    return 0; 
} 
2
class Rectangle {
    int width, height;
  public:
    void set_values (int,int);
    int area (void);
} rect;
1
// C++ program to demonstrate function  
// declaration outside class 
  
#include <bits/stdc++.h> 
using namespace std; 
class Geeks 
{ 
    public: 
    string geekname; 
    int id; 
      
    // printname is not defined inside class definition 
    void printname(); 
      
    // printid is defined inside class definition 
    void printid() 
    { 
        cout << "Geek id is: " << id; 
    } 
}; 
  
// Definition of printname using scope resolution operator :: 
void Geeks::printname() 
{ 
    cout << "Geekname is: " << geekname;  
} 
int main() { 
      
    Geeks obj1; 
    obj1.geekname = "xyz"; 
    obj1.id=15; 
      
    // call printname() 
    obj1.printname(); 
    cout << endl; 
      
    // call printid() 
    obj1.printid(); 
    return 0; 
} 
1
class class_name {
  access_specifier_1:
    member1;
  access_specifier_2:
    member2;
  ...
} object_names;
0
class Name {
  private:
  	int data;
  
  public:
  
    // Constructor
  	Name() {
		// Code      
    }
  	int id;
  	void fun1(int a) {
        // Some instructions here 
    }
 	 
}
0

New to Communities?

Join the community