본문 바로가기

정규 강의/Object-Oriented Data Structures in C++

1.2 C++ Classes

sources: Object-Oriented Data Structures in C++, University of Illinois at Urbana-Champaign, Wade Fagen-Ulmshneider

 

C++ Header File (.h)

 

a header file defines the interface to the class, which includes:

  • Declaration of all member variables
  • Declaration of all member functions
  • Not implementation(how those work) of above
  • Looks like
#pragma once

class Cube {

	public:
    	double getVolume();
        double getSurfaceArea();
        void setLength (double length);
        
    private:
    	double length_;
        
};

C++ CPP file (.cpp)

#include "Cube.h"

double Cube::getVolume() {
	return length_* length_ * length_;
}
 
double Cube::getSurfaceArea() {
	return 6 * length_ * length_;
}

void Cube::setLength(double length) {
	length_ = length;
}
   

 

C++'s Standard Library (std)

 

iostream

 

The iostream eader includes operations for reading/writing to files and the console itself, including std::cout.

 

'정규 강의 > Object-Oriented Data Structures in C++' 카테고리의 다른 글

C++ Copy Assignment Operator  (0) 2019.10.03
C++ Copy Constructor  (0) 2019.10.03
C++ Class Destructors  (0) 2019.10.03
C++ Pointers  (0) 2019.10.01