|
class base{
virtual void operator=(*this object) = 0;
};
Why is that code invalid for the compiler?
what i need to do is to force all inhereted classes to realize this operator for their own class type.
is there a way of doing this?
Thanks.
|
|
|
|
|
If you're trying to define a base class that requires that classes derived from it implement their own assignment operator, try this:
class Base {
virtual Base& operator=(const Base& value) = 0;
};
Software Zen: delete this;
|
|
|
|
|
not exactly.
the purpose is to make the derived classes realize this method, however, the paramater of the method is the class itself (the one that realizes the method), which means that every class that derives from this base class will actually have a different parameter.
|
|
|
|
|
Does this help?
template<class T>
class base
{
public:
virtual T& operator=(const T& assignFrom) = 0;
protected:
~base() {}
};
class Foo : public base<Foo>
{
public:
virtual Foo& operator=(const Foo& assignFrom)
{
return *this;
}
};
Curiously Recurring Template[^]
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts your aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
i can't use templates. my code is meant for multi platform.
is there another way of doing this?
|
|
|
|
|
From your original question - why doesn't this work, it is because *this is a reference to an object, not an actual type.
virtual void operator=(*this object) = 0;
What are you really trying to achieve? If you want to be able to polymorphically assign objects you should look into the virtual constructor idiom and Co-variant return types. C++ FAQ Lite 20.6 - What is a "virtual constructor"?
AFAIK there is no standard portable way to extract the name of a class from an object without using templates or relying upon facilities built into specific compilers - all of which are far less standard than templates (which are now common and robust in C++). I believe that at one stage GCC had an experimental typeof operator. Some alternative implementations of typeof operators do exist however they all rely heavily upon templates, but even then I'm not sure it would help.
Just as an aside, templates are now implemented in all major C++ compilers, basic template techniques (like the one I demonstrated) will compile under every compilers I know (gcc, vc6, vc7, vc7.1, vc8, comeau, borland, intel, ... the list goes on) - I don't think you can get more platform independant than that.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts your aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
I have a bit of a problem and am not sure how serious it is. I'd appreciate any advice from the programming community here. A couple of months ago, we built a new MFC application using the MFC application wizard within Visual Studio .NET. I knew I wanted to implement a help system but wasn't really sure which one to use at the time. It was a low priority and we mainly just wanted to build the application and make it work first. Not having had much experience with MFC application development, we created the new application project to use winhelp. Now, after further review I've decided that we probably should have set it up to use HTML help. Is it a reasonable process to to manually change the code and files within the project directories? Has anyone ever had to do this? I'm wondering how much of a hassle it is going to be. If anyone has any insight on this or helplful tips, I'd appreciate it.
Right now my plan is to create two new side by side projects one using each kind of help. Then I want to evaluate the files and directories created by the wizard to see what the differences are. Hopefully, I can go back to the original application directories and tweak the settings and files/directories to changeover to HTML help. If anyone knows of a better way let me know. If you think that what I am doing is correct and the only way; let me know that too. I'd appreciate any input.
Thank you.
|
|
|
|
|
Since it sounds like you're a bit unfamiliar with MFC development, I think you're doing the right thing. Comparing the code the wizard generates for different choices will show you the basics on how different things are accomplished.
Another thing you can do is to run the wizard again, creating an application with the same attributes as yours (single or multiple document, view types, etc.) and using the same file and class names, but selecting HTML help this time. You can then cut/paste the bits and pieces you need out of the wizard-generated code into your existing application.
Software Zen: delete this;
|
|
|
|
|
Thanks, it seems like I have successfully done this and can now build and compile. However, the project that use to be the winhelp project, the .chm file is not being built. I thought I had changed all of the differences over and added all of the help directories and files to the project.
I've got the .hhc, .hhk, and .hhp along with the .htm directories. The project settings look exactly the same. But when I build, I can't seem to understand why my .chm file doesn't get built. What triggers this process? I just need a hint so that I can figure this out. Perhaps there is a bad path or something in a resource or .htm file I need to change. Any hints would be appreciated and thanks again for your time.
Regards,
Shawn
|
|
|
|
|
I just wanted to close out this thread. I figured it out. The actual project file itself is built by the application wizard with some directives for compiling the appropriate help file(.chm for HTML help). So you definitely have to use the app wizard to create a new project file. You can continue to use the already developed files such as mainframe.[cpp and h]. But you have to copy in paste in a new project file and recreate the solution as well. Also, the output directory (debug/release) need to be completely cleaned in order to eliminate all previous winhelp files that were compiler generated. Other than that, the process is straightforward. Since I hadn't already implemented a lot of the help associated with winhelp there was not much code to change. Just add a call to EnableHtmlHelp() in your application object constructor. I also had to copy all of files from the app wizard generated hlp directory from the new temp project into the old one so that I had all of the default .htm and .hh* files in the directory for working with the HTML files.
Shawn
|
|
|
|
|
I still use VS 6.0, but I guess my considerations could help.
All you need is to redefine the CWinApp virtual function WinHelp . Then, define a CString member m_strHelpFilePath and put a full path to your .chm in it in CApp::InitInstance . (You can do something different, but the idea is to form and store the .chm path).
Your WinHelp function might look like this:
void CApp::WinHelp(DWORD dwData, UINT nCmd)
{
HWND hwndDesktop = ::GetDesktopWindow();
if (!HtmlHelp(hwndDesktop,
m_strHelpFilePath,
HH_HELP_CONTEXT,
nCmd == HELP_CONTEXT ? dwData : 0)))
{
HtmlHelp(hwndDesktop, m_strHelpFilePath, HH_HELP_FINDER, 0);
}
}
If you want your main frame to own the help window frame, pass m_pMainWnd->GetSafeHwnd() instead of hwndDesktop .
Hope this helps.
|
|
|
|
|
I am under developing graphic programing. I already completed main parts. But there is problem. I used gdi implementing graphics, and so there is aliasing. It looks all figures nasty. I searched all the articles here, but I could not find any articles about antialiasing. Is there any good argorithm to apply antialiasing to my graphics without using gdi+. I also used gdi+, but the performance is not good for my graphics. please help me. thanks in advance.
|
|
|
|
|
The link:
http://alglib.manual.ru/translate.php?location=/graphics/wuline&target=cpp[^]
It is a Russian resource, I guess you don't speak Russian. So, here you are:
#include "ap.h"
void drawwuline(double x1, double y1, double x2, double y2);
double myfrac(double x);
void drawwuline(double x1, double y1, double x2, double y2)
{
double grad;
double xd;
double yd;
double length;
double xm;
double ym;
double xgap;
double ygap;
double xend;
double yend;
double xf;
double yf;
double brightness1;
double brightness2;
int x;
int y;
int ix1;
int ix2;
int iy1;
int iy2;
bool wasexchange;
int tmpint;
double tmpreal;
xd = x2-x1;
yd = y2-y1;
if( xd==0&&yd==0 )
{
return;
}
if( fabs(xd)>fabs(yd) )
{
wasexchange = false;
}
else
{
wasexchange = true;
tmpreal = x1;
x1 = y1;
y1 = tmpreal;
tmpreal = x2;
x2 = y2;
y2 = tmpreal;
tmpreal = xd;
xd = yd;
yd = tmpreal;
}
if( x1>x2 )
{
tmpreal = x1;
x1 = x2;
x2 = tmpreal;
tmpreal = y1;
y1 = y2;
y2 = tmpreal;
xd = x2-x1;
yd = y2-y1;
}
grad = yd/xd;
xend = floor(x1+0.5);
yend = y1+grad*(xend-x1);
xgap = 1-myfrac(x1+0.5);
ix1 = floor(x1+0.5);
iy1 = floor(yend);
brightness1 = (1-myfrac(yend))*xgap;
brightness2 = myfrac(yend)*xgap;
if( wasexchange )
{
setpixel(iy1, ix1, brightness1);
setpixel(iy1+1, ix1, brightness2);
}
else
{
setpixel(ix1, iy1, brightness1);
setpixel(ix1, iy1+1, brightness2);
}
yf = yend+grad;
xend = floor(x2+0.5);
yend = y2+grad*(xend-x2);
xgap = 1-myfrac(x2-0.5);
ix2 = floor(x2+0.5);
iy2 = floor(yend);
brightness1 = (1-myfrac(yend))*xgap;
brightness2 = myfrac(yend)*xgap;
if( wasexchange )
{
setpixel(iy2, ix2, brightness1);
setpixel(iy2+1, ix2, brightness2);
}
else
{
setpixel(ix2, iy2, brightness1);
setpixel(ix2, iy2+1, brightness2);
}
for(x = ix1+1; x <= ix2-1; x++)
{
brightness1 = 1-myfrac(yf);
brightness2 = myfrac(yf);
if( wasexchange )
{
setpixel(floor(yf), x, brightness1);
setpixel(floor(yf)+1, x, brightness2);
}
else
{
setpixel(x, floor(yf), brightness1);
setpixel(x, floor(yf)+1, brightness2);
}
yf = yf+grad;
}
}
double myfrac(double x)
{
double result;
result = x-floor(x);
return result;
}
|
|
|
|
|
thanks a lot. I'll try...
|
|
|
|
|
I just create the text ocx( called testocx.ocx) to load some object.
and load into IE. here is the source for html.
when i click button button it will show message said "OK" but
when I new window (in IE File->New-> Window),
"Error, cannot get dispatch object" message will be shown.
We have the same problem for our company
core program. I put the OCX source(AddObj method) for refrence.
maybe someone can point what is problem.
OCX source*******************************
BOOL CTestocxCtrl::AddObj(LPDISPATCH inserObj)
{
CInsertObj * CCmdTarget pObj = ( CInsertObj *)CCmdTarget::FromIDispatch(
inserObj);
if (!pObj){
AfxMessageBox("Error, cannot get dispatch object");
}
else{
AfxMessageBox("OK");
}
return TRUE;
}
test.html*********************************
<title>
<object id="DTestocx1" style="WIDTH: 354px; HEIGHT: 269px"
classid="clsid:361B6B0E-B8D4-47FD-A373-2F37A801F3CD"><param name="_Version"
value="65536" /><param name="_ExtentX" value="7493" /><param name="_ExtentY"
value="5694" /><param name="_StockProps" value="0" />
|
|
|
|
|
I'm trying to statically link some libraries(Xerces) into my application with VS 2003 .Net. I'm trying to do this by adding the libraries to the "Additional Dependencies" field under the "Linker" section of the project properties. After rebuilding the application with these settings, the application still tries to link to the dynamic versions of the libraries.
Did I miss something?
Thanks
Hua-Ying
|
|
|
|
|
wrong library?
Don't try it, just do it!
|
|
|
|
|
Check the docs, some libraries (like id3lib) require you to #define a symbol differently when you use a static LIB build versus a DLL build.
Also make sure you're not picking up a #pragma comment(lib,"...") in a Xerces header file.
--
I'm Michael Dunn and I approve this post.
Vote Trogdor in oh-four!
|
|
|
|
|
Interesting, I'll check.
Thanks
Hua-Ying
|
|
|
|
|
After having had a look ad Xerces several month ago, too, I recommend to just drop Xerces and just use the much-easier-to-use MSXML3/MSXML4. Should be able to do all the things, Xerces does, too.
--
Affordable Windows-based CMS: www.zeta-producer.de/enu
|
|
|
|
|
Unfortunately I need a cross platform parser. I don't believe MSXML is cross platform.
|
|
|
|
|
Hi
I've now got a piece of code that updates an excel spreadsheet on my desktop. I was impressed - thanks to all the CP article writers that made this possible.
Anyway, I can see a bank of 10 users across from my desk who also want my code to update their spreadsheets - is this where DCOM comes in? I would install a DCOM component on all their clients and get my app to talk to the DCOM which in turn would update the local spreadsheet?
Any other 'simple' ideas would be much appreciated as I have no DCOM experience (or much COM come to think of it!!)
See if anybody can answer before David Crow!
Cheers
Angel
******************************************************
Why prolong the agony, all men must die - Roger Waters
|
|
|
|
|
Can your app be run locally on each machine?
Introducing DCOM would end up giving you more headaches than are good for you Especially if you don't know a lot about COM in the first place.
Have a read of some of these pages[^] to get a flavour of what DCOM is.
Michael
CP Blog [^]
|
|
|
|
|
I am trying to create an object of a class(say class1) in a member function of another class(say class2) on the heap. The trouble is it is asserting on that and i cannot proceed further. If I create a normal object(on stack) and call a member function of class1, the function is unable to access the member variables of its own class(class1). It's making me go nuts. I had earlier tested class1 for correctness but now that it is part of this whole application, I don't know what has happened. Please help me. It is urgent.
|
|
|
|
|
AmorphousP wrote:
The trouble is it is asserting on that...
On what? Show us some relevant code.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|