473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

What this line of code means?

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::CCoIniti alize::eMTAModel);

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

Thanks
Trups

Jul 11 '07 #1
14 2534
On Jul 11, 12:28 pm, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.comwrote:
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::CCoIniti alize::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.

Jul 11 '07 #2
On Jul 11, 11:07 am, Hooyoo <zhao_huy...@126.comwrote:
On Jul 11, 12:28 pm, "Samant.Tru...@gmail.com"

<Samant.Tru...@gmail.comwrote:
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::CCoIniti alize::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

Jul 11 '07 #3
On Jul 11, 9:28 am, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.comwrote:
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::CCoIniti alize::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.
Jul 11 '07 #4
On Jul 11, 9:28 am, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.comwrote:
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::CCoIniti alize::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

Jul 11 '07 #5
On Jul 11, 2:20 pm, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.comwrote:
On Jul 11, 11:07 am, Hooyoo <zhao_huy...@126.comwrote:


On Jul 11, 12:28 pm, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.comwrote:
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::CCoIniti alize::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.

Jul 11 '07 #6
On Jul 11, 11:23 am, Neelesh Bodas <neelesh.bo...@gmail.comwrote:
On Jul 11, 9:28 am, "Samant.Tru...@gmail.com"

<Samant.Tru...@gmail.comwrote:
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::CCoIniti alize::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.

Jul 11 '07 #7
On Jul 11, 1:34 pm, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.comwrote:
On Jul 11, 11:23 am, Neelesh Bodas <neelesh.bo...@gmail.comwrote:
On Jul 11, 9:28 am, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.comwrote:
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::CCoIniti alize::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.

ccLib::CCoInitialize::CoInitialize(ccLib::CCoIniti alize::eMTAModel);
could be.

Jul 11 '07 #8
On Jul 11, 1:57 pm, Neelesh Bodas <neelesh.bo...@gmail.comwrote:
On Jul 11, 1:34 pm, "Samant.Tru...@gmail.com"

<Samant.Tru...@gmail.comwrote:
On Jul 11, 11:23 am, Neelesh Bodas <neelesh.bo...@gmail.comwrote:
On Jul 11, 9:28 am, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.comwrote:
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::CCoIniti alize::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::CCoIniti alize::eMTAModel);
could be.
This line I understand.

Thank you very much for replying
>
- Show quoted text -

Jul 11 '07 #9
On 2007-07-11 06:28, Sa***********@gmail.com 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::CCoIniti alize::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.

--
Erik Wikström
Jul 11 '07 #10
On Jul 11, 2:46 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-07-11 06:28, Samant.Tru...@gmail.com 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::CCoIniti alize::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?
>
--
Erik Wikström- Hide quoted text -

- Show quoted text -

Jul 11 '07 #11
On Jul 11, 3:12 pm, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.comwrote:
On Jul 11, 2:46 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-07-11 06:28, Samant.Tru...@gmail.com 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::CCoIniti alize::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);
Jul 11 '07 #12
Sa***********@gmail.com wrote:
On Jul 11, 2:46 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
>On 2007-07-11 06:28, Samant.Tru...@gmail.com 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::CCoIniti alize::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
Jul 11 '07 #13
Sa***********@gmail.com 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::CCoIniti alize::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::CCoIniti alize::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
Jul 11 '07 #14
>
Why not?

struct X
{
x(int); // constructor
OOOPPSSSS. TYPO. This should be X(int).
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);

Jul 11 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: shine | last post by:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="shine.WebForm1" %> what does Inherits means in this tag, what is the use of it plz explain me regards...
2
by: Fred Armitage | last post by:
I have a fairly complex application written using a vb code-behind dll. However, I'd like to write one particular aspx page utilising in-line code so that it can easily be modified as needed by the...
1
by: redhair | last post by:
In a asp.net page (.aspx) below, I'd like to know the in-line code ("<%Output()%> ) will be executed in which page process lifecycle? thanks. <Script Language="VB" Runat="Server"> Sub...
0
by: Jon Paal | last post by:
what would be the command line code to add an image as a resource to a dll ?
10
by: _mario.lat | last post by:
hallo, what does it means "the function is not thread-safe"? thak you in advance, Mario.
1
by: jebaanandhan | last post by:
Hi all, i have come across the following snippets of code in linux kernel. It would be grateful if somebody clarifies me what does the following code means. Code: reference :...
2
by: Dilip7597 | last post by:
Hello Guys, while checking one of the program, I found one difficulty with my program. there was a condition like (!!a), and I don't know what does it means. So if anybody knows...
1
by: rahullko05 | last post by:
one line code to replace an image without page refresh
1
by: rahullko05 | last post by:
Can anybody help me? to write one line code to render html inside a div element. Thanks.
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.