|
Hello,
I was hoping you could help explain my compile error in using 'const'.
I have an array defined as
<br />
const char* const letters[] = {"one", "two"};<br />
where 'const char*' means I have my elements as constant charcter ptrs (so they can't point to anything else) and 'const letters[]' meaning I have an array of fixed length (I hope that that was correct?).
So I wish to define a ptr at the 1st element and I use
<br />
const char* i = letters;<br />
meaning I want a constant ptr of type char pointing to the 1st element. But I keep getting this compiles error
"cannot convert from 'const char* const[2]' to 'const char*'
If anyone can give me an explanation then that would be great.
Thanks !
|
|
|
|
|
This is not because of the const keyword but because the two types are unrelated: char* i is a pointer to a char array and char* letter[] is an array of pointer to char arrays. So you one is a simple pointer and this other one is an array of pointer. You should do something like this: const char* i = letters[0]; instead
|
|
|
|
|
Thank you for that. It worked! I was wondering was I right in my comments on the 2 uses of const in the array def.?
|
|
|
|
|
minkowski wrote: I was wondering was I right in my comments on the 2 uses of const in the array def.?
Yes, it is correct.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
But I thought that if you refer to an array without the [] its just referring to the 1st element in the array which is equivalent to writing
<br />
const char *p = arr;<br />
which is the same as
<br />
const char *p = arr[0];<br />
but I get a compile error
|
|
|
|
|
minkowski wrote: But I thought that if you refer to an array without the [] its just referring to the 1st element in the array
Not at all: you refer to the address of the first element, which is totally different.
Example: if you have an integer array:
int pIntArray[5];
for (int i=0;i<5;i++)
pIntArray[i] = i;
int Test = pIntArray[0];
int Test2 = pIntArray;
|
|
|
|
|
i understand your example, but const char *i is a ptr and needs to point to the address of an object so why not assign it to the address of the 1st element of the array?
|
|
|
|
|
Because in your example, letters is an array of pointers. Which means that the pointer to the first element of the array is in fact a pointer to a pointer of char array, and not a pointer to a char array. There is one level of indirection more.
In brief, letters is equivalent to char** and i is equivalent to char* (removing the const because that's not part of the problem). So you see, the two pointers are not the same (remember that C++ is a strongly typed language so you won't be able to save a pointer to another one if they are not exactly the same type).
|
|
|
|
|
Ah, ok. now i get it.
thanks for the explanatioN!
|
|
|
|
|
Actually, these are equivalent:
const char *p = arr;
const char *p = &arr[0];
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi,
I'm using a static splitter window in my SDI application. But I want the size of the panes to be constant and dont want the user to change the size of the splitter windows by using the splitter bar.anybody know how to do it
|
|
|
|
|
Derive your own splitter window class, say CSplitterWndEx and override the NcHitTest handler. Here comment out the code written by the appwizard i.e. do not call the base class, before that only return TRUE from the function.
This will take care of your problem
Sunil
|
|
|
|
|
Is it not possible to handle the normal "OnSize" of the pane and refuse it ?
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
OnSize is sent when the size has already changed. So, it is easier to simply not allow to change the size.
|
|
|
|
|
Also, by overriding OnNCHittest the cursor will not change to the resizing cursor. No use giving the user a visual clue that there is resizing and then disallowing it.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
The current header file i have (Winsvc.h) neither contain a definition of the structure "SERVICE_STATUS_PROCESS" nor the function "QueryServiceStatusEx(...)".
I am using Visual C++ 6.0.
Can any body help me with that?
Best Regards,
Simos
|
|
|
|
|
softgrid wrote: The current header file i have (Winsvc.h) neither contain a definition of the structure "SERVICE_STATUS_PROCESS" nor the function "QueryServiceStatusEx(...)".
I am using Visual C++ 6.0.
Can any body help me with that?
Well the documentation says this...
Requirements
Windows NT/2000/XP: Included in Windows 2000 and later.
Header: Declared in Winsvc.h; include Windows.h.
|
|
|
|
|
Download and install a NEWER version of the Platform SDK and make VC point at the new libs and headers - your problem will be solved.
The original VC++ headers and libs were out before some of these newer functions, so it is not found in the WinSvc.H that you posess.
If you DO find it in your header, check for it bracketed by a WIN32 definition.
You need to do something like
#define _WIN32 0x0501
or some such value to make it visible.
They did this so you could target backlevel versions of OS with a build and be warned if you were 'linking' to functions that did not exist at the time.
Any sufficiently gross incompetence is nearly indistinguishable from malice.
|
|
|
|
|
Hi everyone,
since few weeks i look for a solution for my problem.
I like to open my MDI Children with Parameters.
For example if i click an element in a list, his ID will be the parameter for the new Child ( or another view with the details of this ID )
So, the new View must known which ID will be loaded...
Whats the best procedure ?
Big thanks
|
|
|
|
|
baerten wrote: Whats the best procedure
Override your base view class, and add a parameter in the overriden "Create" function to pass the ID.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
Ok, but there i must derive many functions from the Template classes.
I startet like this:
i created a new class, derived from CMDIChildWnd
There i can store all informations i want.
At the Create-Event i associate with the Frame the View:
CCreateContext CC;
CC.m_pNewViewClass = RUNTIME_CLASS ( MyView );
CC.m_pCurrentFrame = this;
MyView* ActView = DYNAMIC_DOWNCAST( MyView, this->CreateView(&CC) );
if(ActView) {
ActView->ShowWindow(SW_SHOW);
ActView->OnInitialUpdate();
// Set this view active
SetActiveView(ActView);
RecalcLayout();
ActView->ResizeParentToFit(FALSE);
//RecalcLayout();
}
it works, but the border of the frame is displayed very confused.
The Minimize&Close Buttons are fixed ( aren't all the time in the right corner )
And the Dialog in the View has a wrong size ...
You have already made an application like this?
I'm more than one week over this problem
Thanks
Sprichst du besser Deutsch? Ou plustot francais?
|
|
|
|
|
I have a difficulty...
when I want to make a LPCSTR variable, I do this:
LPCSTR test = TEXT ("hello");
Now I want to make a LPCSTR,including "hello" + name of a persion, which changes every time.
I can't do below:
CString name = "John";
LPCSTR test = TEXT ("hello" + name);
or
CString name = "John";
name = "hello" + name
LPCSTR test = TEXT (name);
please tell me how to do to achieve that result, or show me some pages related to changes of LPCSTR.
|
|
|
|
|
vtalau wrote: CString name = "John";
LPCSTR test = TEXT ("hello" + name);
This should not be done.
Always use TCHAR types with TEXT and _T , else when you compile with _UNICODE defined it could lead to waste of time.
You can do likewise...
CString name = _T( "Nibu " );
name += _T( "Hello" );
LPCTSTR test = name; There is no need to wrap name inside TEXT() . You should be careful when using statements like
LPCSTR test = name; So always adopt a generic approach. Try to use _T() or TEXT() wherever possible along with their counterparts like LPCTSTR .
|
|
|
|
|
Nibu babu thomas wrote: name += _T( "Hello" );
Just a detail, but this should be
name = L("Hello")+name;
otherwise: "Nibu Hello"
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
Rage wrote: otherwise: "Nibu Hello"
|
|
|
|