|
Is there a way to accomplish this?
I get an error the way it is now
error C2440: 'initializing' : cannot convert from 'const int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
int counts[] doesn't work either
warning C4200: nonstandard extension used : zero-sized array in struct/union
error C2233: '<unknown>' : arrays of objects containing zero-size arrays are illegal
typedef struct
{
int id;
int numCounts;
int *counts;
} Counts;
Counts counts[] =
{
{1, 0, 0},
{2, 10, {100, 101, 102, 103, 104, 105, 106, 107, 108, 109}},
{3, 0, 0},
{4, 0, 0},
{5, 8, {209, 208, 207, 206, 205, 204, 203, 202}},
{6, 5, {300, 301, 302, 303, 304}},
};
int numCounts = sizeof(counts) / sizeof(Counts);
void main()
{
return;
}
Todd Smith
|
|
|
|
|
You can't initialize pointer as an array like this:
int *a;
a = {10,20,30};
You can use only type identifier[] = { /*...*/ }
Pointers should be initialized like this:
int *a;
a = new int[10];
a[0] = 15;
a[]1 = 16;
I suggest you to create a more complex type.
Ñ There is only one MP Ð
|
|
|
|
|
This worked
typedef struct
{
int id;
int numCounts;
int *counts;
} Counts;
int items1[] = {100, 101, 102, 103, 104, 105, 106, 107, 108, 109};
int items2[] = {209, 208, 207, 206, 205, 204, 203, 202};
int items3[] = {300, 301, 302, 303, 304};
Counts counts[] =
{
{1, 0, 0},
{2, 10, items1},
{3, 0, 0},
{4, 0, 0},
{5, 8, items2},
{6, 5, items3},
};
void main()
{
return;
}
Todd Smith
|
|
|
|
|
No! This code doesn't work well! It compiles with no errors, but int *counts; is still just a pointer and it can points only at the *first* element in an array!
Example:
int items1[] = {100, 101, 102, 103, 104, 105, 106, 107, 108, 109};
int* p = items1
in debugger:
Name: value: type:
p 0x0054H1 int*
|- 100 int
You can get access to the second element in an array like this: p++, but if you want to get access to the 11th element, you will get Access Violation and your program will crash!
Ñ There is only one MP Ð
|
|
|
|
|
Maciej Pirog wrote:
You can get access to the second element in an array like this: p++, but if you want to get access to the 11th element, you will get Access Violation and your program will crash!
These are the ways of C++ Arrays. They *ARE* just pointer to some memory.
Maybe the STL std::vector is what you want?
|
|
|
|
|
jhwurmbach wrote:
Maybe the STL std::vector is what you want?
That's what I called "more complex type".
Ñ There is only one MP Ð
|
|
|
|
|
I am opening and compiling some old code in Visual Studio .NET
I've run into a compiling problem..
BEGIN_MESSAGE_MAP(CChildView,CWnd )
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_ERASEBKGND()
ON_WM_SIZE()
ON_MESSAGE(WM_FLIPWINDOW, OnFlipWindow)
END_MESSAGE_MAP()
tells me:
error C2440: 'static_cast' : cannot convert from 'void (__thiscall CChildView::* )(void)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
whats happening here?
the Member Function is:
void CChildView::OnFlipWindow()
Ryan Baillargeon
Software Specialist
Fuel Cell Technologies Inc.
|
|
|
|
|
MFC7 (in VS .NET) uses stricter type checking with message map macros. It looks like you need to replace the return from ‘void’ to ‘LRESULT’. Also make sure you supply the correct function parameters, such as (WPARAM, LPARAM) etc.
More on this here [click on Microsoft Foundation Class (MFC) link]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcedit/html/vcrefWhatsNewLibrariesVisualC70.asp[^]
Static Casting and MFC Message Maps Beginning with Visual C++ .NET, MFC provides stricter type checking for return and parameter types of message handler functions. This new behavior notifies the developer of potential problems by flagging potentially unsafe message handlers with an error message. MFC now uses static casts for ON_MESSAGE, ON_REGISTERED_MESSAGE, ON_THREAD_MESSAGE, and ON_REGISTERED_THREAD_MESSAGE.
For example, in the past a developer could use a member function that returned void instead of LRESULT for ON_MESSAGE or ON_REGISTERED_MESSAGE and compile without any errors. With Visual C++ .NET, the potential miscast is caught and flagged as an error. The developer can fix the potential problem by replacing the return type (with LRESULT) and recompiling.
Hope this helps.
// Fazlul
Get RadVC today! Play RAD in VC++
http://www.capitolsoft.com
|
|
|
|
|
FYI, this feature alleviates the #1 programmer bug in MFC code.
-Nick
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
Look at what the error is telling you. The compiler is expecting a function that takes two params, but you're giving it a function that takes no params. The return type is also wrong. Add the two standard message params (WPARAM and LPARAM) and correct the return value.
--Mike--
Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
When you add a derived CView class to your MFC project how do I relate My View derived Class to my CDocument derived class.
I´m trying to add another view to my MFC project.
|
|
|
|
|
You do it in the InitInstance method of your CWinApp derived application class.
You will find there something like this:
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_TESTDFTYPE,
RUNTIME_CLASS(CTestdfsdDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CTestdfsdView));
AddDocTemplate(pDocTemplate);
You register your new document/view pair by copy-paste-edit:
pDocTemplate = new CMultiDocTemplate(
IDR_MYTYPE,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CMyView));
AddDocTemplate(pDocTemplate);
Don't forget to create document string in resources - see the string of existing document in string table resources for example (IDR_TESTDFTYPE in this case).
Sonork 100.15206;PavelK
|
|
|
|
|
Jose Cruz wrote:
Don't forget to create document string in resources - see the string of existing document in string table resources for example (IDR_TESTDFTYPE in this case).
First of all thank you for your help. Now do you have some explanation for the above phrase.
Every MFC document class has a corresponding definition string in string table resource - ID of the string is ID of the document (IDR_xxx), it defines parameters like name of the document for OLE, filename extension and so on.
You need one for every CDocument derived class in Your project. CDocTemplate class uses it.
It looks like:
NTGen\nNTGen\nNTGen\nNTGen Files (*.mdb)\n.mdb\nNTGen.Document\nNTGen Document
Sonork 100.15206;PavelK
|
|
|
|
|
Hello members,
i try to use the CRichEditView without doc/view architecture.
all works fine, but when i exit the app i get a fatal error.
Do anyone know about that error?
What i have maked:
-i created via app-wizard a SDI app without doc/viw
at the view i changed:
- all "things" from CWnd to CRichEditView
- and i have added macro for IMPLEMENT_DYNCREATE...
Can i use ever CRichEditView without doc/view?
Please help me, i really need help!
thanks
|
|
|
|
|
without more info about the fatal error (ie call stack), i suspect that the view is calling a CDocument function on a null pointer (because there is no document).
|
|
|
|
|
Hello Dan,
thank you for your reply!
I don't have any skills at the doc/view... architecture. Can you please try to find the error in my app? (it's only a little testapp)
How can i upload the testapp to here? Or can i send it to you via enail?
I really need help, i tryed to fix that myself, but i don't have sucess.
And i wrote 3 post's about this on codeguru, and NONE reply to me.
Thank you very much!!!
Fiffi
|
|
|
|
|
i mailed you to zip it up and send it to me at dainelg@bde.com.au.
did you not receive it?
|
|
|
|
|
doh! that should have been danielg@bde.com.au
|
|
|
|
|
Hello Dan,
I have convert the project into doc/view architecture, that deleted the error.
Thank you very much for your help!
|
|
|
|
|
Microsoft Calendar Control 8.0(Mscal.Ocx).
There are some Properties, ie: Month, Year. I can get their values in VB program like "value1 = m_Calendar.Month" , "value2 = m_Calendar.Year".
But how to get "Month","Year" in VC++ program???
Thanks a lot.
David
|
|
|
|
|
I'm programming a database soft.Fortunately,I found and used CGridCtrl(2.24) into my program(list data,print it,and set various features...).I want execute SQL clause and fetch data from relevant tables.But I found it difficult to do that(compared to MS Data Grid , DB Grid,etc).
Could you help me?
Thanks for any help.
Sincerely,Pole.
|
|
|
|
|
Pole wrote:
I want execute SQL clause and fetch data from relevant tables.
I don't think it support it like MS data grid.You have to handle everything yourself in that datagrid.
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
Hi,
Anyone noe what error is this and how to remedy it:
First-chance exception : 0xC0000005: Access Violation.
I cannot seems to find it in the msdn library
|
|
|
|
|
I haven´t seen documenation about it, but it always fires on my screen when my code reads/writes to a unassigned memory block. This happens very usually when working with pointers and new/delete operators. Check all the rountines using dynamic memory allocation before the point that breaks the execution of your application.
"nobody knows it, but you´ve got a secret smile, and you use it only for me"
|
|
|
|
|
it means your process does not have access to the memory it was trying to use. like the previous poster noted, this usually means you have a bad pointer. check all your pointers - make sure they have valid values.
-c
A man is like a rusty wheel on a rusty cart,
He sings his song as he rattles along and then he falls apart.
-- Richard Thompson
|
|
|
|
|