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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -