# output itk built version

**URL:** https://discourse.itk.org/t/output-itk-built-version/940
**Category:** Beginner Questions
**Created:** [May 17, 2018, 7:42am UTC](https://discourse.itk.org/t/output-itk-built-version/940 "2018-05-17T07:42:04Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![pdeman](https://discourse.itk.org/letter_avatar_proxy/v4/letter/p/9fc348/32.png) [@pdeman](https://discourse.itk.org/u/pdeman)
#### Post date: [May 17, 2018, 7:42am UTC](https://discourse.itk.org/t/output-itk-built-version/940/1 "2018-05-17T07:42:04Z")

</div>

Hi,

I have some code using itk libraries, and I would like to display itk built version when calling them.  
#include \<itkVersion.h\>

bool myClass::myClassFuncion()  
{

//get itk version  
itk::Version whichItk;  
std::cout \<\< whichItk.GetITKBuildVersion() \<\< std::endl;  
}  
which is not working as the constructor is “protected” so I get the error:  
‘itk::Version::Version’: cannot access protected member declared in class ‘itk::Version’

I guess there is another solution than declaring all itk class as friend class of mine.  
I must do something wrong when calling the version class.

---

<div class="post-metadata">

### Author: ![jhlegarreta](https://discourse.itk.org/user_avatar/discourse.itk.org/jhlegarreta/32/476_2.png) [@jhlegarreta](https://discourse.itk.org/u/jhlegarreta)
#### Post date: [May 17, 2018, 8:24am UTC](https://discourse.itk.org/t/output-itk-built-version/940/2 "2018-05-17T08:24:07Z")

</div>

@phcerdan Does this [test](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/test/itkVersionTest.cxx) help?

I also remember Brad or Hans having contributed with a quantitative test using **GTest** for testing the ITK version, but am unable to find it now.

---

<div class="post-metadata">

### Author: ![pdeman](https://discourse.itk.org/letter_avatar_proxy/v4/letter/p/9fc348/32.png) [@pdeman](https://discourse.itk.org/u/pdeman)
#### Post date: [May 17, 2018, 11:00am UTC](https://discourse.itk.org/t/output-itk-built-version/940/3 "2018-05-17T11:00:57Z")

</div>

thanks.  
I succed by doing:  
const char \* itkVersion = itk::Version::GetITKVersion();  
std::cout \<\< "itk version: " \<\< itkVersion \<\< std::endl;  
this one works as well:  
itk::Version::Pointer version = itk::Version::New();  
std::cout \<\< version-\>GetITKVersion() \<\< std::endl;

but I am not sure why it works. it’s not calling the constructor ?  
it should.  
why there is no “can’t access protected memeber class” when calling this way ?  
(I guess it’s more a c++ than a itk function, but I don’t understand why I don’t get the error when doing this way)

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 17, 2018, 1:36pm UTC](https://discourse.itk.org/t/output-itk-built-version/940/4 "2018-05-17T13:36:16Z")

</div>

> [@pdeman](#):
>
> itk::Version::Pointer version = itk::Version::New();

`New()` is a member function of `itk::Version` class, so it can access all its members, including **protected** and **private** ones.

And you can access `New()` because it is **public**.

---

<div class="post-metadata">

### Author: ![pdeman](https://discourse.itk.org/letter_avatar_proxy/v4/letter/p/9fc348/32.png) [@pdeman](https://discourse.itk.org/u/pdeman)
#### Post date: [May 17, 2018, 1:52pm UTC](https://discourse.itk.org/t/output-itk-built-version/940/5 "2018-05-17T13:52:19Z")

</div>

and new is inherited from Object i guess

ok thanks for the explanation.  
(and sorry for the dumb question …)

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 17, 2018, 1:59pm UTC](https://discourse.itk.org/t/output-itk-built-version/940/6 "2018-05-17T13:59:23Z")

</div>

`New` is a macro, defined in [itkMacro.h](https://github.com/InsightSoftwareConsortium/ITK/blob/b0f183b04fd78062afafea26636b4dc597651b88/Modules/Core/Common/include/itkMacro.h#L246-L297) and used by pretty much every descendant of `Object`, including [Version](https://github.com/InsightSoftwareConsortium/ITK/blob/b0f183b04fd78062afafea26636b4dc597651b88/Modules/Core/Common/include/itkVersion.h#L69). Thus `New` is not an inherited member, but rather direct member defined in `Version`.

---

<div class="post-metadata">

### Author: ![pdeman](https://discourse.itk.org/letter_avatar_proxy/v4/letter/p/9fc348/32.png) [@pdeman](https://discourse.itk.org/u/pdeman)
#### Post date: [May 18, 2018, 8:43am UTC](https://discourse.itk.org/t/output-itk-built-version/940/7 "2018-05-18T08:43:29Z")

</div>

> New() is a member function of itk::Version class  
> because of this : `itkNewMacro(Self);` ?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [May 18, 2018, 11:49am UTC](https://discourse.itk.org/t/output-itk-built-version/940/8 "2018-05-18T11:49:24Z")

</div>

Yes. That macro creates a few member functions, including `New()`.

---

<div class="post-metadata">

### Author: ![pdeman](https://discourse.itk.org/letter_avatar_proxy/v4/letter/p/9fc348/32.png) [@pdeman](https://discourse.itk.org/u/pdeman)
#### Post date: [May 18, 2018, 11:58am UTC](https://discourse.itk.org/t/output-itk-built-version/940/9 "2018-05-18T11:58:54Z")

</div>

thanks a lot for all explanations.
