-4

In visual studio I am trying to get started with c++. I created a class and it's helper file. I see in the helper file that there are two constructors declared. One with and one without the ~ sign. Like this:

Age::Age()
{
}


Age::~Age()
{
}

I am trying to google this, but I can not find out what it means. This is my first question. How to google something with special characters in them since the google search engine seems to have problems with these and filter them out.

Second I want to give an example. I tried to google "What does ::~ mean constructor c++" with zero actual hits, and maybe you can give me an answer of that, but I am sure there must be an answer already out there. But as stated before, I can't find that since somehow special characters are hard (or not possible at all?) to find using the google search engine.

Joop
  • 3,706
  • 34
  • 55
  • 1
    Open up any beginner C++ book and it will explain what destructors are. –  Feb 08 '15 at 15:10
  • 2
    possible duplicate of [The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) –  Feb 08 '15 at 15:10
  • 1
    ~ marks a destructor of a class which is called when object of this class is being deleted/destructed – Michał Walenciak Feb 08 '15 at 15:10
  • ~Age is the destructor. Time to get out your book. – drescherjm Feb 08 '15 at 15:10
  • 1
    BTW, destructors have nothing to do with Google – ForceBru Feb 08 '15 at 15:11
  • 2
    Arguably off-topic instead of a dupe, as it belongs on [Web Applications](http://webapps.stackexchange.com/). –  Feb 08 '15 at 15:11
  • Please make your title consistent with the body of the question. – juanchopanza Feb 08 '15 at 15:13
  • You can expect to get a lot of disrespect when asking these types of questions. I do not understand that. Life is about learning. Yet no one has answered my question. I only got a partial answer. – Joop Feb 08 '15 at 15:15
  • @Joop which question do you need an answer for, the one in the title or the one in the body of your question. The latter has been answerd by Arun. The first is offtopic. – wimh Feb 08 '15 at 15:17
  • @Wimmel Maybe the first one is off-topic but this creates a loop in which users keep asking the same questions because they can't find the answers to them and were people over here keep bashing over duplicates. So instead if someone knows how to google this kind of queries properly, if that's possible at all, then there could possibly benefit a lot of people from it. – Joop Feb 08 '15 at 15:22
  • [How can I search for a keyword with special characters in Google Search?](http://webapps.stackexchange.com/q/23) [How to search the internet for terms with special characters](http://webapps.stackexchange.com/q/1479) – wimh Feb 08 '15 at 15:24
  • @Wimmel good to know that it is not possible to work around this. Only with other search engines. – Joop Feb 08 '15 at 15:27

2 Answers2

2
Age::~Age()

is a destructor.

It does the exact opposite work of a constructor, that is it destroys the object when its scope is over.

Visit these links to understand better

http://www.tutorialspoint.com/cplusplus/cpp_constructor_destructor.htm

http://www.cprogramming.com/tutorial/constructor_destructor_ordering.html

If you want to know more about it just search for destructor c++ on google

This link might help you for your first question

How can I use a search engine to search for special characters?

https://webapps.stackexchange.com/questions/23/how-can-i-search-for-a-keyword-with-special-characters-in-google-search

Community
  • 1
  • 1
Arun A S
  • 6,421
  • 4
  • 29
  • 43
1

The symbol "~" before a constructor makes it a destructor. a destructor automatically executes functions when an object is destroyed. ie when the object is destroyed do this. othewise the constructor executes functions when an object is created.

JoeG
  • 12,994
  • 1
  • 38
  • 63
waipa mark
  • 46
  • 3