Creating an assigning an object in c++ -


hello new c++,

i can create new instance of class using example example("123")

i have 2 question

  1. i know cannot check if object null if(example ==null) because not pointer have other way that.

  2. i have method return object like: how can return null?

    example get_example() {     if (example.getname().empty() {         example example("345");         return example;     }     return null // cannot return null. } 

can this?

example get_example() {     example example;     if (example.getname().empty() {         example = example example("345");          return example;     }     return null // cannot return null. how  } 

example = example example("345"); know stupid how can without pointer.

  1. use pointers, example *ex = null.

  2. construct default null_example , overload ==

    example e; if (e == null_example) {     e.init(); } 
  3. but provide is_init() function.

    example e; if (!e.is_init()) {      e.init(); } 
  4. you get_example like:

    void get_example(example &e) {      // method2 or method3 } 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -