COM SCI 32 Lecture Notes - Lecture 2: Init, System Resource

26 views4 pages

Document Summary

Class cylinder { private: int radius; int height; public: void init(r. h) make a simple class first, just get the public interface right later make the implementation more efficient. Constructors: just use name of the class as the name of the function, no return type: class gassy public: Gassy(int age, bool atebeans) m_age = age; m_atebeans = atebeans; private: int m_age; bool m_atebeans; Contsructor automatically called every time you create a new variable of that class. You can also define constructor outside the class declaration (class declaration could be in . h while some functions are defined in . cpp) For small proejctes, its easier to put everything in the class declaration. For bigger projects, it might be faster to define some functions outside. Gassy alan; // compiler error, no constructor with 0 parameters another constructor: Gassy lec1[4]; when you call a ptr, it does not call the constructor. Gassy *ptr = new gassy(1,3); // constructor is called when you use new.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents