|
as title. The code and the error messages are posted as follows. VS2005 + wtl. I checked some articles and references on polymorphism and operator overload, but haven't figured out the problems. So why it's wrong? How to correct it? Thanks in advance.
Basically the classes are used to query values (can be interpreted to different built-in types e.g. dword, char*, etc.) according to key.
Code: (you can copy it into your VC++ compiler and try)
-----
#include "stdafx.h" // wtl required
class ObjValue
{
};
class ObjKey
{
public:
class ObjValueProxy {
public:
ObjValue QueryValue() const;
operator ObjValue() const;
};
};
ObjValue ObjKey::ObjValueProxy::QueryValue() const
{
ObjValue* v = new ObjValue;
return *v;
// i don't care the value in this example
// in reality, it's the result of some query action
}
operator ObjKey::ObjValueProxy::ObjValue() const
{
return QueryValue();
}
Errors:
------
Compiling...
testoperatoroverloading.cpp
d:\test\testoperatoroverloading.cpp(25) : error C2039: 'ObjValue' : is not a member of 'ObjKey::ObjValueProxy'
d:\test\testoperatoroverloading.cpp(10) : see declaration of 'ObjKey::ObjValueProxy'
d:\test\testoperatoroverloading.cpp(26) : error C2270: '.?AVObjValue@@' : modifiers not allowed on nonmember functions
d:\test\testoperatoroverloading.cpp(26) : error C2801: 'operator ObjValue' must be a non-static member
d:\test\testoperatoroverloading.cpp(27) : error C3861: 'QueryValue': identifier not found
test - 4 error(s), 0 warning(s)
|
|
|
|
|
Try this:
class ObjValue
{
int i;
};
class ObjKey
{
public:
class ObjValueProxy {
public:
ObjValue QueryValue() const;
operator ObjValue() const {return QueryValue();}
};
};
ObjValue ObjKey::ObjValueProxy::QueryValue() const
{
ObjValue* v = new ObjValue;
return *v;
}
Memory leak...
ObjValue* v = new ObjValue;
return *v;
|
|
|
|
|
right... i haven't paid attention to the memory leak since it was created to reproduce the problem in my real project...
i know it would compile in the way you proposed, but i prefer putting them outside in a separate .cpp file. and! reason has actually been found out! The correct form should be
ObjKey::ObjValueProxy::operator ObjValue() const
instead of
operator ObjKey::ObjValueProxy::ObjValue() const
Thanks anyway!
|
|
|
|
|
Cool!
|
|
|
|
|
I am porting an application from Win2000 to WINXP using visual studio 2005 standard edition. I am calling the network functions: WNetCancelConnection2 and WNetAddConnection2. I have attached a code snippet. The drive maps and unmaps correctly. No errors are returned when the functions are called. However, if I remap a drive with the same letter to a different server, the windows explorer label is not updated. It displays the old server name. If I click on properties, it shows the correct server. This works correctly in Win2000. I am mapping to unix servers running PC Net Link or SAMBA. Anyone seen this issue. Any suggestions on what to do.
----------------------------------------
Code snippet:
CMapDialog dlg;
if( dlg.DoModal() == IDOK )
{
CWaitCursor cWaitCursor;
DWORD dwStatus= WNetCancelConnection2(strDriveLetter, CONNECT_UPDATE_PROFILE, TRUE);
m_strCurrentMapping = _T("Unmapped");
if( dlg.GetMap() )
{
CString strShare(dlg.GetShareName());
NETRESOURCE nr;
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = strDriveLetter;
nr.lpRemoteName = strShare.GetBuffer(256);
nr.lpProvider = NULL;
if( (dwStatus = WNetAddConnection2(&nr, NULL, NULL, CONNECT_UPDATE_PROFILE)) == NO_ERROR )
{
strErrorText.Format(IDS_MAP_OK, strDriveLetter, strShare);
OutputToEvents(strErrorText, INFO);
}
else
{
strErrorText.Format(IDS_MAP_ERROR, strDriveLetter, GetLastError(), GetLastErrorText());
OutputToEvents(strErrorText, FATAL);
}
m_strCurrentMapping = GetMapString();
}
UpdateMapString();
}
}
}
Fred Shaw
|
|
|
|
|
fred shaw wrote: However, if I remap a drive with the same letter to a different server, the windows explorer label is not updated. It displays the old server name.
What happens if you try and access that server? Does WE try the older server or the new one?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
It accesses the new server, however the old server name is being displayed which is wrong since it is pointing to the new server.
Fred Shaw
|
|
|
|
|
I have subclassed a few controls (the win32 method not MFC) and am now trying to prevent flickering while the control is being moved around the main window. Basically, all I want to do is prevent the control from painting itself while the main window is being resized. I am able to trap the WM_MOVE message, but unable to trap the WM_ENTERSIZEMOVE or WM_EXITSIZEMOVE messages. I'm guessing these are only sent to the top level window. Can anybody suggest an alternative to determining when a control starts moving and ends moving?
|
|
|
|
|
It sounds like the entire client area of the background window is being repainted every time
a WM_PAINT occurs.
In the window's WM_PAINT handler if you are not using BeginPaint() you can make a clipping
region to only draw the newly exposed part of the window using GetUpdateRect (make sure you
validate the rect with ValidateRect() so you don't get repeated WM_PAINT messages for the same
rect).
Or maybe it's happening in a WM_ERASEBKGND handler in the window or control
Mark
|
|
|
|
|
Mark Salsbery wrote: Or maybe it's happening in a WM_ERASEBKGND handler in the window or control
Both the main window and the control have a bitmap skin applied to them. For the main window, each time it is resized I must rebuild the bitmap used for the skin and repaint it to the window. This is naturaly done in the WM_ERASEBKGND handler.
I will have a play with the clipping region and see if I can better the performance a little.
A simple hack I came up with is to draw the child controls image to the main windows image. The flickering is still there, but cannot be seen.
|
|
|
|
|
Does using the WS_CLIPCHILDREN style on the main window help at all?
|
|
|
|
|
I have to access tables from MicroSoft Access and read write its contents.
|
|
|
|
|
sujeet_kulk wrote: I have to access tables from MicroSoft Access and read write its contents.
OK? What specifically did you want to know?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I have to change(/read) data in Microsoft Access Tables (data base tables) through Automation( using object model of MS Access (not through ODBC)) in MFC.
|
|
|
|
|
sujeet_kulk wrote: I have to change(/read) data in Microsoft Access Tables (data base tables) through Automation( using object model of MS Access (not through ODBC)) in MFC.
I got that much from your initial post. What you are asking, however, is very broad. It can't be answered in a simple post.
Do you need to add Access' type library to your project?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
No I have added that, atleast name the classes and methods involved and sequence if possible.
|
|
|
|
|
sujeet_kulk wrote: ...name the classes and methods involved...
They are in the .h and .cpp files that were added to your project. The first one you'll need is _Application . Call its CreateDispatch() method.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Fine with that but how to get the rows and columns of a datatable, I mean which are the classes.
|
|
|
|
|
sujeet_kulk wrote: ...which are the classes.
Have you looked at AccessObject ?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi,
I want to compress the video data using XviD codec. How I can set this codec as default codec for compression in "AVISaveOptions" API which displays a dialog box to user. I don't want to show that dialog box but instead it should use the default codec from. How can set the default codec value?
Regards,
Hemant.
|
|
|
|
|
I have following line of code:
if(a==Z||<br />
b==Z||<br />
c==Z||<br />
d==Z||<br />
e==Z||<br />
f==Z||<br />
g==Z)<br />
{<br />
.<br />
.<br />
.<br />
} can this be written in a better way ?
p.s all the variables are of type enums
|
|
|
|
|
How about:
if (a <= Z && Z <= g)
... Of course, trying to one-up the optimizer is usually a lost cause.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Is Z a enumeration value or a variable? If they are all variables, you really can't do much without making assumptions about ordering for the values.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Can Somebody help me..
i have one ListBox and one combobox . i want that when user select any item in the ListBox , the path of that item is got selected in the combobox..
How to achieve this..
Please help me in this..
Thanks and Regards
|
|
|
|
|
step1:
In the ui designer, right click the control (combobox) and
click 'wizard'.
You can add an event to it.
Then, an event function will be created in the classes you chose.
step2:
Add code in the event function.
Something like this->GetDlgText(...)
|
|
|
|