c++ - Return variable as a Class Object -


i have created string class using character array.

i need place array instead of class object. here's easy example.

i want print a integer , not b class object isn't possible.

#include <iostream>  class t  {    int ;     public : t ( )    {        = 10 ;    } } ;  void main ( ) {     t b ;     std :: cout << b ; } 
  1. is possible?

  2. okay, how?

you need output stream operator:

std::ostream& operator <<(std::ostream& o, const t& t) {   return o << t.a; } 

note that, since a private, have friend of t.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -