|
I did present a simple solution. Reread my post?
|
|
|
|
|
What you're trying to do is strange. The compiler is behaving correctly. When you say "cout << this << endl; " this is an instance of B so that's what's being passed to the << operator.
I also don't understand what you mean by: it shows B's data instead of A's. B's data is also A's. B is just an extended version of A. I don't see how the two would be different. Perhaps you could extend your example to show what you mean by A's data vs. B's data.
In case you haven't, here's a couple more things to try inside your operator:
1. (A)a.some_data
2. a.A::some_data
Regards,
Alvaro
Hey! It compiles! Ship it.
|
|
|
|
|
Thanks for replying.
I am NOT disputing the compiler at any time is wrong; just the opposite (which is why I am still looking for a way to get what I'm trying to accomplish.)
It is because the compiler is right, why the code (the way it's shown in the example) is "showing B's data instead of A's." By that I mean, because 'ShowExpandedInfo' is activated from inside a B's function, the "this" pointer is physically and logically referring to 'B' as its object, and is what gets shown. It has nothing here to do with 'B' being a part of 'A' due to the inheritance relationship.
While it is true that B's data is also A's (due to the inheritance relationship), the converse is NOT true (that 'A' is a part of 'B'). Therefore, when 'B' uses a pointer to refers to data (as "this" in the case at hand), even if that pointer could be used to access A's data, what you end up getting, is strictly B's data.
Yes, there is the matter of explicit casting, but that is something I prefer to stay away from (for the time being) and use ONLY as the very last resort.
Thanks again for replying.
William
Fortes in fide et opere!
|
|
|
|
|
I'll bite...
This may not be the solution you need, but you could make the ShowExpandedInfo() method virtual and in the derived class you could call A::ShowExpandedInfo(). The bad thing is, it would probably show A and B.
A better solution might be to get a B pointer instead and cast it however you want it to be used. Like this:
A* ptrA = NULL;
B* ptrB = new B;
ptrA = (A*)B;
ptrA->RunOuterLoop();
ptrB->RunOuterLoop();
You can pass ptrA around and cast it back to a B* since that's what it really is. I've got some code at work doing this sort of thing so if my memory of this is wrong I can look it up tomorrow.
"It is better to remain silent and be thought a fool than to open one's mouth and remove all doubt." - Abraham Lincoln
|
|
|
|
|
Thanks for replying.
What you have suggested regarding the explicit casting of a pointer to 'B', cast as a pointer to 'A', has some merit and may work. I say this because I haven't tried the explicit casting of pointers yet (and will do so ONLY as the very last resort).
I've chosen to try polymorphism, friend functions and even "slicing" (though this is just as bad as explicit casting, except you don't have to re-cast things back to set everything back in sync).
My hope was that someone might know of a clever way using friend function, smart pointer or even overloading the 'member access operator' (alias: the "->" operator).
This quest is NOT over. As Churchill adequately put it, "This is not the end. It's not even the beginning of the end. It's only the end of the beginning." The first round went to the compiler, and we are just starting the second round.
William
Fortes in fide et opere!
|
|
|
|
|
Hello,
I would like to set the intermediate files path from the Project Settings > Settings For > Win32 Debug/Release > General tab to a global folder. It would allow me to build my projects in a temporary folder that I can delete and clean up any time without deleting nor affecting my working projects.
Its default value is Debug or Release, depending of the configuration you select, Win32 Debug or Win32 Release (for a MFC application). I created an environment variable named "vcc_tmp". Using the command line I can change the current directory to that folder using "chdir %vcc_tmp%". Windows knows that it has to replace %vcc_tmp% by its value.
So I tried it with VC++ but it doesn't replace the variable by its value, "%vcc_tmp%\MyApp\Debug" doesn't work. It creates a new folder named "%vcc_tmp%".
The problem is that a lot of people are working on many projects. Lot of people, lot of projects. So I can't affort choosing "static" path for all these projects. Each developers would have to create an environment variable "vcc_tmp" and set it to its temp folder. I don't want to choose "c:\vcc_tmp" as some people can't use their c: drive to store temp files. Moreover using the OS drive as a tmp drive is not a good idea, defrag, scan... No no no .
So if you have any remarks and suggestions or solutions, don't hesitate to reply to that thread. All help is welcome.
Kind regards,
JM. Molina
Earth > Europe > France > Lyon
|
|
|
|
|
Hello all,
Currently, I need to write a program which allows the users to select a specific folder on the hard drive. However, I only know how to use MFC to allow the users to select specific file on the drive by using "GetOpenFileName()". Is there any way which allows users to select a folder rather than a file in MFC?
Thanks!!!!
Nachi
|
|
|
|
|
SHBrowseForFolder() or you could use one of the many folder selection dialogs at CP.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Sorry,
I am not really know how to use this function, is there any example so that I can study on, thanks!
Nachi
|
|
|
|
|
Yes, MSDN Library.
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
|
I know this is a visual c++ forum and I'm really sorry, but this seems to be the only lounge where I get the best answers to questions, so please don't get too mad that this question is a little more general and not focused solely on visual c++.
On a normal coordinate system, the Y-Axis is positive in the upward direction and X-Axis in the right direction, which naturally makes the Z-Axis positive coming towards you. On a computer screen, however, we still measure the X-Axis as positive to the right, but now the Y-Axis is positive going downward, so is the Z-Axis now positive away from the viewer?
I'm asking this for finding the normal line to a polygon on the monitor, trying to determine if it is front or back facing. I just need to know for sure if I'm doing this correctly or not.
Again, sorry this isn't really a C++ question, but I think the people in this forum are the best with quick and intelligent responses!
Douglas A. Wright
dawrigh3@kent.edu
|
|
|
|
|
AFAIK X-axis is always positive to the right, Z-axis is always positive towards the viewer, and Y-axis is positive up in every mode except text mode, in which case it is positive down.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
That is correct, for OpenGL. You can of course change between left hand and right hand coords in both OpenGL and Direct3D.
|
|
|
|
|
Can anyone tell me how to get around problems created by Norton AV and other antivirus software? For instance, a lot of products on the market are realtime products. They record music, they play music, they create documents, and so forth. How have people gotten around how Norton AV realtime protection handles files? I cannot be the only person who has problems with a product that creates files and Norton AV interferes with this, can I? Am I making any sense?
I was once told that if you have a product that creates files, antivirus software locks the file when it is scanning. And to get around such problems, you have to work with Symantec. Does anyone know for certain?
|
|
|
|
|
I've been using NAV for years, even before Symantec entered the picture, with no problems. You can configure it to ignore certain file extensions.
|
|
|
|
|
I have never seen that issue. It sounds like BS to me. Who told you NAV 'locks' files? If it is true, I have never seen/heard of it. Anyway, you should set NAV to only scan program files. Scanning MP3, AVI, etc is a waste of time.
|
|
|
|
|
Hi,
I can access the doc from the view this way:
CGeneratorDoc * pDoc = GetDocument();
How do I access the view from the doc?
|
|
|
|
|
One quick and dirty way is to create a dummy project with the view to create as CEditView. This in effect creates a notepad like application. You can then look at the Doc to see how it is done. I never remember exactly how, but this is how I go find out. Also, there is a way to get the view (if it is a SDI and you will not be attaching anymore). Look in the MSDN for artical Q108587.
Good Luck
Larry J. Siddens
Cornerstone Communications
TAME THE DOCUMENT MONSTER
www.unifier.biz
|
|
|
|
|
Use GetFirstViewPosition() /GetNextView() .
|
|
|
|
|
I'm still getting errors.
This is SDI application and I have two FormViews. I am trying to access functions of the first view class from the document.
I'm doing the following in the document class:
POSITION pos = GetFirstViewPosition();
CView* pFirstView = GetNextView( pos );
(CMyView *)pFirstView-> Function();
But, I'm getting errors which points to the declaration of the GetDocument() in the view class as following:
c:\rulegenerator\generator.v.13.0\generator.v.5.0\generatorview.h(34) : error C2143: syntax error : missing ';' before '*'
c:\rulegenerator\generator.v.13.0\generator.v.5.0\generatorview.h(34) : error C2501: 'CGeneratorDoc' : missing storage-class or type specifiers
c:\rulegenerator\generator.v.13.0\generator.v.5.0\generatorview.h(34) : error C2501: 'GetDocument' : missing storage-class or type specifiers
Generator.cpp
.......
Please help
|
|
|
|
|
Which one of these lines is it on? It is complaining about something in the view.h. Make sure that the doc.h file is before the view.h in the #include list.
Larry J. Siddens
Cornerstone Communications
TAME THE DOCUMENT MONSTER
www.unifier.biz
|
|
|
|
|
even after casting the view to my view class, i can't access view class functions.
POSITION pos = GetFirstViewPosition();
CView* pFirstView = GetNextView( pos );
(CGeneratorView *)pFirstView-> OnPopupRemove();
error:
C:\RuleGenerator\Generator.V.14\Generator.v.5.0\GeneratorDoc.cpp(633) : error C2039: 'OnPopupRemove' : is not a member of 'CView'
c:\program files\microsoft visual studio\vc98\mfc\include\afxwin.h(3542) : see declaration of 'CView'
|
|
|
|
|
Yeah, it isn't. Included the header for your view. Make sure it is after the doc.h. That should solve your problem.
Larry
Larry J. Siddens
Cornerstone Communications
TAME THE DOCUMENT MONSTER
www.unifier.biz
|
|
|
|
|
i have included view header after the doc header, still the casting is not working.
|
|
|
|