473,395 Members | 2,689 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,395 software developers and data experts.

One more way windows can ruin your day

Hi,

///////////////////////////////////////////////
// File Module.h

struct Object
{
static Object *GetObject(int i);
};

///////////////////////////////////////////////
// File Module.cpp

#include "Module.h"
#include <windows.h>

Object *Object::GetObject(int i)
{
return NULL;
}

Now invoke MS C++ compiler on module.cpp:

cl.exe module.cpp

And you get:

Module.cpp(7) : error C2039: 'GetObjectA' : is not a member of 'Object'
Module.h(5) : see declaration of 'Object'

Besides GetObject, they have also macro-redefined lots of other useful
names, such as 'DrawText' or 'MessageBox'. This is _really_ annoying.

Best regards,
Marcin

Jul 22 '05 #1
4 1506
>
Besides GetObject, they have also macro-redefined lots of other useful
names, such as 'DrawText' or 'MessageBox'. This is _really_ annoying.


Simple, don't use camel notation

get_object, draw_text, message_box, you know it makes sense.

john
Jul 22 '05 #2
John Harrison wrote:
...
Besides GetObject, they have also macro-redefined lots of other useful
names, such as 'DrawText' or 'MessageBox'. This is _really_ annoying.


Simple, don't use camel notation

get_object, draw_text, message_box, you know it makes sense.
...


Actually, it was Pascal notation :) So its more like "better _use_ camel
notation".

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #3

"John Harrison" <jo*************@hotmail.com> wrote in message
news:c1*************@ID-196037.news.uni-berlin.de...

Besides GetObject, they have also macro-redefined lots of other useful
names, such as 'DrawText' or 'MessageBox'. This is _really_ annoying.


Simple, don't use camel notation

get_object, draw_text, message_box, you know it makes sense.


And more to the point, one needs to pay attention to any
libraries one is using(*), and not step on their names.
C++ namespaces help greatly with this. Since the Windows
API is not in a namespace (it's mainly intended as a C
interface), you can insulate your names from it by putting
your own code in a namespace(s) (except 'main()', that is).

<OT>
Marcin:

Those symbols 'GetObject', 'DrawText', 'MessagBox', are names
from the Windows API. Many of these are macros which expland
to the same names with either 'A' or 'W' suffixes depending upon
a #define, for choosing between ASCII and Unicode. That's
"Just The Way It Is". Those who don't like it can simply choose
not to use the API, but perhaps some 'wrapper' library.

(*)What, you're not using the Windows API? Then what's the
windows.h there for? I don't see anything in your code that
uses it. Remove it, and then you can use those symbols
as your own.

And if I'm writing code that *does* use the Windows API, I
don't use their 'camel case' for my own symbols, it makes
it obvious which symbols are from the API, and which not.
(except for the all-uppercase macro names of course).

</OT>
-Mike
Jul 22 '05 #4
Then don't include windows.h!

windows.h is just like *any* other C include file. Name collisions and and
will exist.
Marcin Kalicinski wrote:

Hi,

///////////////////////////////////////////////
// File Module.h

struct Object
{
static Object *GetObject(int i);
};

///////////////////////////////////////////////
// File Module.cpp

#include "Module.h"
#include <windows.h>

Object *Object::GetObject(int i)
{
return NULL;
}

Now invoke MS C++ compiler on module.cpp:

cl.exe module.cpp

And you get:

Module.cpp(7) : error C2039: 'GetObjectA' : is not a member of 'Object'
Module.h(5) : see declaration of 'Object'

Besides GetObject, they have also macro-redefined lots of other useful
names, such as 'DrawText' or 'MessageBox'. This is _really_ annoying.

Best regards,
Marcin

Jul 22 '05 #5

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

Similar topics

44
by: Truble | last post by:
Visual Studio .NET is not more efficient to write than VB6. I can write a VB6 App at least twice as fast as in .NET. Why did Microsoft ruin the syntax advantage of VB6 in .NET?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.