3 Replies - 2038 Views - Last Post: 10 December 2013 - 03:15 PM

#1 npanagakis  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 01-December 12

What is the point of the void function?

Posted 10 December 2013 - 02:50 PM

So I am learning C++, and I came across the void function. What I read told me that it is the same thing as a regular function but it does not return a variable. Whats the point of this? Couldn't you just leave the return statement out of a regular function?
Is This A Good Question/Topic? 0
  • +

Replies To: What is the point of the void function?

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8364
  • View blog
  • Posts: 31,073
  • Joined: 12-June 08

Re: What is the point of the void function?

Posted 10 December 2013 - 02:55 PM

No you can't. If a function does not have a return option then that sort of pisses off compilers.. if the return type doesn't match the header that tends to piss off a compiler.. what data type and value would you feel is representative of "this function returns nothing"?

void is a solid way to flag a method as just a subroutine that does stuff and doesn't need to report back a value.
Was This Post Helpful? 1
  • +
  • -

#3 npanagakis  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 01-December 12

Re: What is the point of the void function?

Posted 10 December 2013 - 03:08 PM

View Postmodi123_1, on 10 December 2013 - 02:55 PM, said:

No you can't. If a function does not have a return option then that sort of pisses off compilers.. if the return type doesn't match the header that tends to piss off a compiler.. what data type and value would you feel is representative of "this function returns nothing"?

void is a solid way to flag a method as just a subroutine that does stuff and doesn't need to report back a value.

Ah, thanks for the reply. It makes sense now, though I did exclude a return statement in a regular function, it did not return any errors, perhaps this is because I am using ming. I'd assume with other compilers I'd have an error.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8364
  • View blog
  • Posts: 31,073
  • Joined: 12-June 08

Re: What is the point of the void function?

Posted 10 December 2013 - 03:15 PM

Yeah.. IDEs like Visual Studios will pitch a fit if a function has paths that all do not reach a return statement.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1