|
thanks russel,
but can you suggest me some idea such that it always sits on top of all the posts. like that of chris maunder.
|
|
|
|
|
|
Wow I said what happend you used of B tags;) its good idea.;)
|
|
|
|
|
Hi all.
Here are the two classes one base and other Derived ( virtually inherited from Base)
Class Base
{
Public:
Virtual void FunB(){}
};
Class Derived: virtual public Base
{
Public:
Virtual void FunD(){}
};
When I derived class Derived virtually from Base, and when I saw the memory layout of objects of Derived in debug window; I saw two separate vfptrs; one for Base and one for Derived.
But if I do not derive class Derived virtually from Base, then there is only single vfptr in object of Derived class?
Why an extra vfptr is added/required in case of virtual inheritance?
Sameer Thakur
|
|
|
|
|
Try reading this article[^] in the C++ FAQ, especially section 25.9 on virtual inheritance.
Software Zen: delete this;
|
|
|
|
|
Hi,
How can find handle to the treeitem if i know its path in a tree control.
-- modified at 4:33 Saturday 1st September, 2007
|
|
|
|
|
See GetNextItem(handle to item on the tree,here flags you can use for example TVGN_CHILD
|
|
|
|
|
Thanks,but i don't have any handle.I have only path(for ex: A\Apple\fruit).What i need is handle to the tree item "fruit".How to get it.
|
|
|
|
|
Here some function on the CTree class that you can use of them for get handle to root GetRootItem and GetParentItem. but I think you are new to this section so I suggest see articles on the codeproject about CTree.
|
|
|
|
|
You have to use the GetRootItem() and GetNextItem() [^] member functions in the CTreeCtrl class to traverse the nodes in the tree. Use the GetItem() function to retrieve information about each node, including the node's text. Compare the node's text to that part of the 'path'.
For example, if the path is C:\Forest\Orchard\Apple, start at the root and look for the node with the text 'Forest'. Within the nodes attached to the 'Forest' node, look for one with the text 'Orchard', and so on.
I'll give you a hint: a recursive routine is the way to go here.
Software Zen: delete this;
|
|
|
|
|
I am a fairly new Visual c++ user and probably have a newbie question to ask.
I am using Visual Studio c++ v6.0 cs2 I think.
I have an array of combo box values to read in from an extremely rudimentary dialog box all created with the use of the graphical tools as much as possible.
The normal way to read data in from MFC controls seems to be to asign a variable to exchange data with the control with DDX commands and UpdateDate();.
Did I mention that I the array is fairly large? Discovering that the DDX statement doesn't even use the control's IDtag, but only the #define integer, I decided that using a large number of variables and thus a large number of DDX statements was a lot of unnecessary code and a lot of time defining variables, so I decided to get a little clever. Probably too clever...
I noticed that the resource.h file associates each control item keyword with an integer value with a #define. So I edited that file and the control box integers to reflect a series of integers that I could read control data into an array of variables with a nested for loop and one single DDX statement for a 9x9 array of combo boxes.
for (i=0; i<9; i++) {<br />
for (j=0; j<9; j++)<br />
{<br />
DDX_Text(pDX, (1000+(10*j)+i), CSarray[i][j]);<br />
}<br />
}<br />
This actually works great . . . until, for some unexplained reason, I try to access items [6][7], [6][8], [7][6], [7][7], [7][8], [8][6], [8][7], and [8][8].
Strangely enough [6][6] works fine. These values represent the far corner combo boxes of the array.
The above code always compiles fine, but I get a run-time error - "Debug Assertion Failed!" on some file dlgdata.cpp line 43 (I have never seen this file) and I have tracked the problem by accessing each of the 81 possibilities manually. All other values read in with this method fine.
I DID have to change some other values in this file to move them out of the range of integer values I chose to make this work. (A few button controls which work fine and maybe the _APS_NEXT_CONTROL_VALUE whatever that is.) Still compiles fine. I noticed that resource.h is a header file for the ProjectName.rc file (which I don't understand at all).
So I don't have any idea what to try next. I suspect I am stepping over some value assignment limit or have a value conflict, but don't know why 1080 would work as a value when 1078 doesn't.
|
|
|
|
|
your problem seems to be solvable, but your narration is a bit confusing. so if you dont mind, you can forward me your source code, such that, i can clean it and tell you the solution.
or you can also forward me a better narration with the screen shots.
|
|
|
|
|
Here is my Resource.h:
<small>
#define IDM_ABOUTBOX 0x0010<br />
#define IDD_ABOUTBOX 100<br />
#define IDS_ABOUTBOX 101<br />
#define IDD_WINSS_DIALOG 102<br />
#define IDR_MAINFRAME 128<br />
#define IDI_POOKA_LOGO 130<br />
<br />
#define IDC_A1 1000<br />
#define IDC_A2 1001<br />
#define IDC_A3 1002<br />
#define IDC_A4 1003<br />
#define IDC_A5 1004<br />
#define IDC_A6 1005<br />
#define IDC_A7 1006<br />
#define IDC_A8 1007<br />
#define IDC_A9 1008<br />
<br />
#define IDC_B1 1010<br />
#define IDC_B2 1011<br />
#define IDC_B3 1012<br />
#define IDC_B4 1013<br />
#define IDC_B5 1014<br />
#define IDC_B6 1015<br />
#define IDC_B7 1016<br />
#define IDC_B8 1017<br />
#define IDC_B9 1018<br />
<br />
#define IDC_C1 1020<br />
#define IDC_C2 1021<br />
#define IDC_C3 1022<br />
#define IDC_C4 1023<br />
#define IDC_C5 1024<br />
#define IDC_C6 1025<br />
#define IDC_C7 1026<br />
#define IDC_C8 1027<br />
#define IDC_C9 1028<br />
<br />
#define IDC_D1 1030<br />
#define IDC_D2 1031<br />
#define IDC_D3 1032<br />
#define IDC_D4 1033<br />
#define IDC_D5 1034<br />
#define IDC_D6 1035<br />
#define IDC_D7 1036<br />
#define IDC_D8 1037<br />
#define IDC_D9 1038<br />
<br />
#define IDC_E1 1040<br />
#define IDC_E2 1041<br />
#define IDC_E3 1042<br />
#define IDC_E4 1043<br />
#define IDC_E5 1044<br />
#define IDC_E6 1045<br />
#define IDC_E7 1046<br />
#define IDC_E8 1047<br />
#define IDC_E9 1048<br />
<br />
#define IDC_F1 1050<br />
#define IDC_F2 1051<br />
#define IDC_F3 1052<br />
#define IDC_F4 1053<br />
#define IDC_F5 1054<br />
#define IDC_F6 1055<br />
#define IDC_F7 1056<br />
#define IDC_F8 1057<br />
#define IDC_F9 1058<br />
<br />
#define IDC_G1 1060<br />
#define IDC_G2 1061<br />
#define IDC_G3 1062<br />
#define IDC_G4 1063<br />
#define IDC_G5 1064<br />
#define IDC_G6 1065<br />
#define IDC_G7 1066<br />
#define IDC_G8 1067<br />
#define IDC_G9 1068<br />
<br />
#define IDC_H1 1070<br />
#define IDC_H2 1071<br />
#define IDC_H3 1072<br />
#define IDC_H4 1073<br />
#define IDC_H5 1074<br />
#define IDC_H6 1075<br />
#define IDC_H7 1076<br />
#define IDC_H8 1077<br />
#define IDC_H9 1078<br />
<br />
#define IDC_I1 1080<br />
#define IDC_I2 1081<br />
#define IDC_I3 1082<br />
#define IDC_I4 1083<br />
#define IDC_I5 1084<br />
#define IDC_I6 1085<br />
#define IDC_I7 1086<br />
#define IDC_I8 1087<br />
#define IDC_I9 1088<br />
<br />
#define IDC_ABOUT_BUTTON 2000<br />
#define IDC_CONSOLE_BUTTON 2001<br />
#define IDCLEAR 2002<br />
#define ID_CLEAR_BUTTON 2002<br />
#define IDSOLVE 2003<br />
#define ID_SOLVE_BUTTON 2003<br />
#define IDC_POOKA_BYLINE 2004<br />
#define IDC_POOKA_LOGO 2005<br />
<br />
#ifdef APSTUDIO_INVOKED<br />
#ifndef APSTUDIO_READONLY_SYMBOLS<br />
#define _APS_NEXT_RESOURCE_VALUE 134<br />
#define _APS_NEXT_COMMAND_VALUE 32771<br />
#define _APS_NEXT_CONTROL_VALUE 2000<br />
#define _APS_NEXT_SYMED_VALUE 101<br />
#endif<br />
#endif</small>
Here is the code from the ProjectNameDlg.cpp file meant to retreive the data from the 9x9 array of combo box controls:
<small> CString CSarray[9][9];<br />
<br />
int i,j;
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
int a= 6;<br />
int b= 6;<br />
<br />
for (i=0; i<9; i++) {<br />
for (j=0; j<9; j++)<br />
{<br />
DDX_Text(pDX, (1000+(10*j)+i), CSarray[i][j]);<br />
}<br />
}<br />
}<br />
<br />
</small>
I am getting a "Debug Assertion Failure! (File:dlgdata.cpp line 43 - which doesn't exist)" for the 8 combo boxes commented above. I cannot find a logical reason why these controls cause this failure when none of the others do. Is there some limitation of Visual c++ v6.0 on the number of control boxes allowed?
|
|
|
|
|
The Problem eventually solved itself. Turns out, when modifying one of the control's label and re-saving the dialog editor window, the problem just went away. Must be some feature of Visual c++ that has a copy of the information somewhere else that needs to be updated.
Very strange (and annoying) behavior. But case closed.
|
|
|
|
|
This one has left me scracthing my head. I want to define a constant array in an implementation file. I'd like to treat it as a read only table. So in my implementation file I have this:
const unsigned char Sawtooth[] =
{
};
In my header file, I have this:
extern const unsigned char Sawtooth[];
When I try to build the solution, I get an unresolved external symbol error. If I remove const from both the declaration and the definition, it compiles fine. It's as though the const modifier is making the definition private to the implementation file, like the static modifier does.
I don't remember having this problem using C. Is this a C++ or Visual Studio "gotcha" that I've not been aware of before? Or is there something else I'm overlooking?
|
|
|
|
|
It works for me on VS 2005.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: It works for me on VS 2005.
It seems to have a problem when I assign the const array to a member variable in one of my classes. So in one of my classes, I have this:
private:
const unsigned char *wavetable;
And I have a setter method in the same class:
void Oscillator::SetWavetable(const unsigned char *wavetable)
{
assert(wavetable != 0);
this->wavetable = wavetable;
}
If I remove the assignment, the compiler error goes away. I don't understand what the problem is. I'm declaring/defining a const unsigned char array in an implementation file. I pass it to the above method and for some reason the compiler is treating it as a "unsigned char const * const", according to the compiler error message.
|
|
|
|
|
Leslie Sanford wrote: seems to have a problem when I assign the const array to a member variable
I don't see any code assigning an array to a member variable.
Your code shown built fine for me as well
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Leslie Sanford wrote: I'm declaring/defining a const unsigned char array in an implementation file. I pass it to the above method
Pass it how?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Pass it how?
It's passed to the setter from the constructor. So in the Sawtooth.cpp file, I have the const array defined:
const unsigned char Sawtooth[] =
{
};
In my Wavetable.h file, I have the declaration:
extern const unsigned char Sawtooth[];
In my Oscillator class, I have an const unsigned char pointer member:
class Oscillator
{
private:
const unsigned char *wavetable;
public:
void SetWavetable(const unsigned char *wavetable);
};
In my constructor I do this:
#include "Wavetable.h"
Oscillator::Oscillator()
{
SetWavetable(Sawtooth);
}
In other words, I want the wavetable member to point to the Sawtooth array when an Oscillator is created.
[EDIT]
Oscillator.obj : error LNK2019: unresolved external symbol "unsigned char const * const Sawtooth"
That's part of the error message. It's as if the compiler wants to treat my Sawtooth array as an unsigned char const * const.
[/EDIT]
|
|
|
|
|
Again, this compiles and links for me
Leslie Sanford wrote: error LNK2019: unresolved external symbol "unsigned char const * const Sawtooth"
Are you sure you are linking Sawtooth.cpp?? The problem's in linking.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Again, this compiles and links for me
I should have paid more attention when you said this before instead of continuing to assume there was a problem with const.
If I include the header file in the implementation file that has the const array, everything works correctly; no more linking errors:
Wavetable.h:
extern const unsigned char Sawtooth[];
Sawtooth.cpp:
#include "Wavetable.h"
const unsigned char Sawtooth[] =
{
};
I'm not sure why, but including the header file in my Sawtooth.cpp file solved the problem. I can keep the const modifier.
|
|
|
|
|
Leslie Sanford wrote: I'm not sure why, but including the header file in my Sawtooth.cpp file solved the problem.
Cool.
Here's what the docs state:
"Declaration of const variables with the extern storage class forces the variable to have
external linkage. An initialization of an extern const variable is allowed in the defining
translation unit. Initializations in translation units other than the defining translation unit
produce undefined results."
I guess the definition needs the extern declaration as well on static const variables (?)
Cheers!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I think I've figured out the problem. Arrays are const by default. That is the array variable is const, not its contents. This is illegal:
unsigned char a[100];
unsigned char b[100];
a = b;
So declaring an array as const...
const unsigned char a[100];
...seems to be interpretted by the compiler as unsigned char const * const, whatever the heck that is. An unsigned char const pointer to const... something.
At any rate, it does not evaluate to const unsigned char *. So when I tried passing it to the setter method, the compiler seemed to have a problem with that. If I remove the const modifier on the array, it compiles and runs ok.
What I was intending was to make an arrays contents read only. I haven't figured out how to do that.
|
|
|
|
|
The probem is not the const.
const unsigned char Sawtooth[] = {0,1,2,3,4,5,6,7,8,9};
If you try ...
Sawtooth[0] = 1;
...you'll see the compiler won't let you.
Passing Sawtooth as a const unsigned char * will work as well.
The assignment shown above won't work as you've seen - you need to deep-
copy the array contents from one to the other. Note if the destination is const
you won't be able to unless you cast away the const.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|