Constructor
Apr 10, 2019 at 2:40am UTC
I am trying to understand what does this line of code means.
I know is a constructor but i dont understand what does the second ':' refers to?
Any help is greatly appreciate.
1 2
TestTargetAccess::TestTargetAccess()
: ITargetAccess("TestTarget" )
When I compile, i am getting this error
error: ‘TestTargetAccess’ does not name a type;
Thank you so much for your help.
Apr 10, 2019 at 4:05am UTC
That isn’t a whole lot of context, but if you are using Embarcadero’s component library, then you cannot instantiate an interface.
The compile error looks like you have not #included the class definition in your .cpp file.
The single colon is what begins the constructor’s
initializer list .
https://en.cppreference.com/w/cpp/language/initializer_list
It is just another way of initializing variables in your object.
1 2 3 4 5 6 7 8 9 10 11 12
struct Quux
{
int a, b;
double c;
Quux() :
a(7), // a = 7
b(), // default initialize b (int = 0)
c(3.141592) // c = PI
{ }
...
Hope this helps.
Topic archived. No new replies allowed.