Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Teatime Snack
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//g++ 7.4.0 //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> #include <string> using namespace std; class Snack;//Snack will declare a friend class so this solitary line is needed. class Teatime{ int price, plate; public: int cost() { return (price *plate); } void get(Snack a); }; class Snack{ friend class Teatime;//class Teatime is declared a friend to class Snack; so Teatime members have access to Snack class members; not the other way as Teatime did not treat class Snack as friend. private: int price, qty; public: Snack (int p, int q) : price (p), qty(q) {} }; void Teatime::get(Snack a) { price = a.price; plate= a.qty; } int main() { Teatime tt; Snack s(5,4); tt.get(s); cout <<"Tea time snack costs Tk "<<tt.cost()<<endl; return 0; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.54 sec, absolute running time: 0.18 sec, cpu time: 0.02 sec, memory peak: 5 Mb, absolute service time: 0,88 sec
edit mode
|
history
|
discussion
Tea time snack costs Tk 20