What this line of code means?

S

Samant.Trupti

Hi all,

I have some code that I am unable to understand. Can you please
help?

int _tmain(int argc, _TCHAR* argv[])
{
// Initialize COM environment.
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
....
}
1. CCoInitialize is a class
to invoke a object of class you write
CCoInitialize cc;
2. CoInitialize is static function.
to invoke static function you write scope resolution "::"

ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);

when they have "space" instead of "::" what is that mean? What are
they trying to do?

Thanks
Trups
 
H

Hooyoo

Hi all,

I have some code that I am unable to understand. Can you please
help?

int _tmain(int argc, _TCHAR* argv[])
{
// Initialize COM environment.
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
...}

1. CCoInitialize is a class
to invoke a object of class you write
CCoInitialize cc;
2. CoInitialize is static function.
to invoke static function you write scope resolution "::"

ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);

when they have "space" instead of "::" what is that mean? What are
they trying to do?

Thanks
Trups

I think ccLib is a namespace, and that line means to instantiate
class CCoInitialize that is defined in namespace ccLib.
 
S

Samant.Trupti

I have some code that I am unable to understand. Can you please
help?
int _tmain(int argc, _TCHAR* argv[])
{
// Initialize COM environment.
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
...}
1. CCoInitialize is a class
to invoke a object of class you write
CCoInitialize cc;
2. CoInitialize is static function.
to invoke static function you write scope resolution "::"

when they have "space" instead of "::" what is that mean? What are
they trying to do?
Thanks
Trups

I think ccLib is a namespace, and that line means to instantiate
class CCoInitialize that is defined in namespace ccLib.- Hide quoted text -

- Show quoted text -

Thanks for your answer. Yes ccLib is a namespace. I still have a
question
CoInitialize(ccLib::CCoInitialize::eMTAModel); returns HRESLT so this
function should be
HRESULT result = CoInitialize(ccLib::CCoInitialize::eMTAModel);
and ccLib::CCoInitialize cclib; this should be instantiation
what do you mean when you combine both?
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
That space (CCoInitialize CoInitialize) I am confuse with.

Thanks
 
N

Neelesh Bodas

Hi all,

I have some code that I am unable to understand. Can you please
help?

int _tmain(int argc, _TCHAR* argv[])

Thats not std C++. what is _tmain? what is _TCHAR* ?
{
// Initialize COM environment.
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);

Let us assume that this is an initialization since your comments say
so. (BTW, since you have not given any context of what eMTAModel is,
this expression could very well be treated as a function declaration
also)
...}

1. CCoInitialize is a class
to invoke a object of class you write
CCoInitialize cc;
2. CoInitialize is static function.
to invoke static function you write scope resolution "::"

ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);
when they have "space" instead of "::" what is that mean? What are
they trying to do?

There is no general rule like "spaces instead of ::" etc. In
your_specific_example, the first statement declared and initialized
'CoInitialize' as an object of the class ccLib::CCoInitialize. The
second statement invoked the CoInitialize static member function of
the class ccLib::CCoInitialize.
 
D

doublemaster007

Hi all,

I have some code that I am unable to understand. Can you please
help?

int _tmain(int argc, _TCHAR* argv[])
{
// Initialize COM environment.
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
...}

1. CCoInitialize is a class
to invoke a object of class you write
CCoInitialize cc;
2. CoInitialize is static function.
to invoke static function you write scope resolution "::"

ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);

when they have "space" instead of "::" what is that mean? What are
they trying to do?

Thanks
Trups

Can this be like this?

CoInitialize(ccLib::CCoInitialize::eMTAModel) is function which
returns CCoInitialize whic is defined in namespace ccLib
 
H

Hooyoo

Hi all,
I have some code that I am unable to understand. Can you please
help?
int _tmain(int argc, _TCHAR* argv[])
{
// Initialize COM environment.
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
...}
1. CCoInitialize is a class
to invoke a object of class you write
CCoInitialize cc;
2. CoInitialize is static function.
to invoke static function you write scope resolution "::"
ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);
when they have "space" instead of "::" what is that mean? What are
they trying to do?
Thanks
Trups
I think ccLib is a namespace, and that line means to instantiate
class CCoInitialize that is defined in namespace ccLib.- Hide quoted text -
- Show quoted text -

Thanks for your answer. Yes ccLib is a namespace. I still have a
question
CoInitialize(ccLib::CCoInitialize::eMTAModel); returns HRESLT so this
function should be
HRESULT result = CoInitialize(ccLib::CCoInitialize::eMTAModel);
and ccLib::CCoInitialize cclib; this should be instantiation
what do you mean when you combine both?
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
That space (CCoInitialize CoInitialize) I am confuse with.

Thanks- Hide quoted text -

- Show quoted text -

God, are you kidding me?
CoInitialize(ccLib::CCoInitialize::eMTAModel) should be the construct
function for class ccLib::CoInitialize.
 
S

Samant.Trupti

I have some code that I am unable to understand. Can you please
help?
int _tmain(int argc, _TCHAR* argv[])

Thats not std C++. what is _tmain? what is _TCHAR* ?
{
// Initialize COM environment.
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);

Let us assume that this is an initialization since your comments say
so. (BTW, since you have not given any context of what eMTAModel is,
this expression could very well be treated as a function declaration
also)
1. CCoInitialize is a class
to invoke a object of class you write
CCoInitialize cc;
2. CoInitialize is static function.
to invoke static function you write scope resolution "::"
ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);
when they have "space" instead of "::" what is that mean? What are
they trying to do?

There is no general rule like "spaces instead of ::" etc. In
your_specific_example, the first statement declared and initialized
'CoInitialize' as an object of the class ccLib::CCoInitialize. The
second statement invoked the CoInitialize static member function of
the class ccLib::CCoInitialize.

Thanks again. I understood that. eMTAModel is enum define.
CoInitialize is a static function in CCoInitialize class. The thing
I want to know is
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel); is
this one of the way to call staic function? I always used "::" instead
od space.
 
N

Neelesh Bodas

Hi all,
I have some code that I am unable to understand. Can you please
help?
int _tmain(int argc, _TCHAR* argv[])
Thats not std C++. what is _tmain? what is _TCHAR* ?
Let us assume that this is an initialization since your comments say
so. (BTW, since you have not given any context of what eMTAModel is,
this expression could very well be treated as a function declaration
also)
There is no general rule like "spaces instead of ::" etc. In
your_specific_example, the first statement declared and initialized
'CoInitialize' as an object of the class ccLib::CCoInitialize. The
second statement invoked the CoInitialize static member function of
the class ccLib::CCoInitialize.

Thanks again. I understood that. eMTAModel is enum define.
CoInitialize is a static function in CCoInitialize class. The thing
I want to know is
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel); is
this one of the way to call staic function? I always used "::" instead
od space.

ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
is *not* a call to static function.

ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);
could be.
 
S

Samant.Trupti

On Jul 11, 9:28 am, "(e-mail address removed)"
Hi all,
I have some code that I am unable to understand. Can you please
help?
int _tmain(int argc, _TCHAR* argv[])
Thats not std C++. what is _tmain? what is _TCHAR* ?
{
// Initialize COM environment.
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
Let us assume that this is an initialization since your comments say
so. (BTW, since you have not given any context of what eMTAModel is,
this expression could very well be treated as a function declaration
also)
...}
1. CCoInitialize is a class
to invoke a object of class you write
CCoInitialize cc;
2. CoInitialize is static function.
to invoke static function you write scope resolution "::"
ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);
when they have "space" instead of "::" what is that mean? What are
they trying to do?
There is no general rule like "spaces instead of ::" etc. In
your_specific_example, the first statement declared and initialized
'CoInitialize' as an object of the class ccLib::CCoInitialize. The
second statement invoked the CoInitialize static member function of
the class ccLib::CCoInitialize.
Thanks again. I understood that. eMTAModel is enum define.
CoInitialize is a static function in CCoInitialize class. The thing
I want to know is
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel); is
this one of the way to call staic function? I always used "::" instead
od space.

ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
is *not* a call to static function.

Ok. So what is this code does? Because I am debugging someones code
it has this line.
ccLib is namespace, CCoInitialize is a class, static function
CoInitialize in CCoInitialize, eMTAModel enum
ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);
could be.
This line I understand.

Thank you very much for replying
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Hi all,

I have some code that I am unable to understand. Can you please
help?

int _tmain(int argc, _TCHAR* argv[])
{
// Initialize COM environment.
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
...
}
1. CCoInitialize is a class
to invoke a object of class you write
CCoInitialize cc;
2. CoInitialize is static function.
to invoke static function you write scope resolution "::"

ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);

when they have "space" instead of "::" what is that mean? What are
they trying to do?

It creates an instance of the CCoInitialize class called CoInitialize,
the parameters passed to the constructor is CCoInitialize::eMTAModel.
 
S

Samant.Trupti

I have some code that I am unable to understand. Can you please
help?
int _tmain(int argc, _TCHAR* argv[])
{
// Initialize COM environment.
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
...
}
1. CCoInitialize is a class
to invoke a object of class you write
CCoInitialize cc;
2. CoInitialize is static function.
to invoke static function you write scope resolution "::"
ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);

when they have "space" instead of "::" what is that mean? What are
they trying to do?

It creates an instance of the CCoInitialize class called CoInitialize,
the parameters passed to the constructor is CCoInitialize::eMTAModel.

The thing is CoInitialize is a static function of class
CCoInitialize. Is it possible to have funtion name and instatnce name
same?
 
K

Kai-Uwe Bux

I have some code that I am unable to understand. Can you please
help?
int _tmain(int argc, _TCHAR* argv[])
{
// Initialize COM environment.
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
...
}
1. CCoInitialize is a class
to invoke a object of class you write
CCoInitialize cc;
2. CoInitialize is static function.
to invoke static function you write scope resolution "::"
ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);

when they have "space" instead of "::" what is that mean? What are
they trying to do?

It creates an instance of the CCoInitialize class called CoInitialize,
the parameters passed to the constructor is CCoInitialize::eMTAModel.

The thing is CoInitialize is a static function of class
CCoInitialize. Is it possible to have funtion name and instatnce name
same?

Yes. Even the following is legal:

#include <iostream>
#include <ostream>

struct X {

void operator() ( void ) const {
std::cout << "called\n";
}

};

void x ( void ) {
std::cout << "not called\n";
}

int main ( void ) {
X x;
x();
}


Note, however, that ccLib::CCoInitialize::CoInitialize is in a different
namespace and also local to the CCoInitialize class. Regardless,
re-choosing that name it is a BadIdea(tm).


Best

Kai-Uwe Bux
 
N

Neelesh Bodas

On 2007-07-11 06:28, (e-mail address removed) wrote:
Hi all,
I have some code that I am unable to understand. Can you please
help?
int _tmain(int argc, _TCHAR* argv[])
{
// Initialize COM environment.
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
...
}
1. CCoInitialize is a class
to invoke a object of class you write
CCoInitialize cc;
2. CoInitialize is static function.
to invoke static function you write scope resolution "::"
ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);
when they have "space" instead of "::" what is that mean? What are
they trying to do?
It creates an instance of the CCoInitialize class called CoInitialize,
the parameters passed to the constructor is CCoInitialize::eMTAModel.

The thing is CoInitialize is a static function of class
CCoInitialize. Is it possible to have funtion name and instatnce name
same?

Why not?

struct X
{
x(int); // constructor
static void Foo(int); // static member function
};

X::Foo(5); // calls static function
X Foo(5); //creates an instance Foo of class X using X::X()

Foo.Foo(5); // calls the static function using the instance.

Note that the last line above is -
a) syntactically not an error
b) semantically equivalent to X::Foo(5);
 
S

Stuart Redmann

Hi all,

I have some code that I am unable to understand. Can you please
help?

int _tmain(int argc, _TCHAR* argv[])
{
// Initialize COM environment.
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
...
}
1. CCoInitialize is a class
to invoke a object of class you write
CCoInitialize cc;
2. CoInitialize is static function.
to invoke static function you write scope resolution "::"

ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);

when they have "space" instead of "::" what is that mean? What are
they trying to do?

As we don't know what the headers of this library look like (I searched for
ccLib and found only a library for computation chemistry), we can only guess.
My guess is that CoInitialize is treated as the name of a newly created object
of type ccLib::CCoInitialize. And this would even makes sense: If you want to
ensure that the code inside _tmain is run in a Microsoft COM (Component Object
Model) MTA (multi-threaded apartment), you can use CoInitialize as guard (since
it is an object, it will be destroyed at the end of _tmain, which will certainly
lead to a call to ::CoUninitialize of the COM API in the destructor of
ccLib::CCoInitialize). Of course it is a bad idea to name an object like a
function, as this can easily lead to confusion.

To summarize:
ccLib::CCoInitialize CoInitialize(ccLib::CCoInitialize::eMTAModel);
creates an object called CoInitialze of class ccLib::CCoInitialize.

ccLib::CCoInitialize::CoInitialize(ccLib::CCoInitialize::eMTAModel);
calls the static class function ccLib::CCoInitialize::CoInitialize.

As both method make sure that your main thread enters a multi-threaded
apartment, both ways may to the job (although the second way of calling the
static function leaves your thread inside the apartment when the applications
quits, I can't image what will happen if you forget to call ::CoUninitialize).
The preferable way is surely the first.

Regards,
Stuart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top