I want to know how I can create an array/object at runtime if I don’t know about its data type.
I have an array Say Arr, but I don’t have any information about the data type of elements it stores. It might be an array of int, float, char or even user defined data type (user defined class).
I can get the information about its class or data type by using ‘type_info’, but how can I create an array/object of same data type at runtime?
Like if I want to copy the contents of an array Arr into another array say ‘NewArr’; of the same type at runtime, how can I create that second array NewArr, i.e. what should I specify as a data type of ‘NewArr’?
how can I create an array/object of same data type at runtime?
AFAIK, there's no way to do this directly in C++.
You can, however, design a system of classes that are capable of creating/cloning themselves at
runtime and/or being created by type.
For an example implementation, check out the source code for MFC's CRuntimeClass and CObject
classes and the DECLARE_DYNAMIC/IMPLEMENT_DYNAMIC macros. This implementation has a common
base class which includes methods for runtime object creation based on a class name.
Because C++ has no built-in way to do this, the CRuntimeClass implements a list that maps
class names to creator functions.
Depending on the source of your source arrays, serialization may be useful as well.
Regardless, at the heart of these solutions is code that creates objects of a specific class,
which is all that C++ allows.
Just my 2-cents,
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
I am trying to create a custom window caption for SDI application.I have
taken help from http://www.codeproject.com/gdi/customcaption.asp
The project on the above link use WM_NCPAINT,WM_NCACTIVATE and WM_SETTEXT handlers in the window procedure to draw and paint the caption bar.In this
project whole caption bar has been customized.
In my application,I don't want to draw and paint minimize,maximize and close buttons and let them be like the system's created default buttons.Actually these default buttons are getting drawn and painted but are not visible when the mainframe window gets activated.When I move the mouse on that region, then only those buttons are visible and work fine on clicking them.So, Can you please suggest me why those buttons may not be getting visible when the mainframe window gets activated?
i am developing a com add-in for MSWord in MFC, and i need to get the current UI language of the MSWord to make it the UI language of the add-in
i know that there is a method in the application class called get_LangaugeSetting , but in MFC this will retrun a dispatch, i need the LanguageSettings class to attach it with the dispatch
and i dont know where to get this class from
I am creating a dialog based application with a CWebBrowser2 control. I need to print the page displayed in the browser in landscape or portrait format without displaying the PrintDialog. Landscape or Portrait is decided by some other inputs.
I have two methods in my App class for setting the orientation and for starting the printing. Now the probelm for me is how to get the content in the browser or in other words how to get the html displayed in the browser? what to do after a m_Browser.GetDocument() call ?? I dont know how I can associate the html with DOCINFO structure ( setting the file name does not work of course). Landscape/Portrait modes and a dc.TextOut() for a hardcoded string works fine. But how to print the html displayed in the browser?
Please note: setting the orientation and using the ExecWb() function does not work because I am always getting portrait mode only.
Guys....any tips regarding this ?? Setting printing orientation, getting the content from a Webbrowser control and printing it. I dont want the print dialog to appear and the ExecWb() method always prints in portrait.
Hi ! I?'ve an application developed using MFC. When I run the project, a window will open. If I close the window manually (i.e by clicking the cross mark at the top left corner of the window), then an exception occurs.
Unhandled exception at 0x7c918fea in Perspective.exe: 0xC0000005: Access violation writing location 0x00000010.
If I break this exception,
Program control goes to a file called free.c
the yellow arrow shows what file/function you are watching in VS, look at that!...and walk forward on the tree to find a function in your code (not in external dll) that do something wrong (than double cliche on that function on the call stack window).
Usually the error is in the first function that you will reach, and usually the real error could be in less than 10 lines before the line related to the crash...but it depends on your code.
I clicked all the lines from the beginning of Call Stack. When I Click a New
Line the Green Triangle goes either to a system file(like free.c) or to a inline file(.inl file like nicriticalsection.inl).
ni stands for Net Immerse Game Engine(previously called NetImmerse New Name is Gamebryo).
It did not go to any of the function defined by me. I should not change any ofthese system files or inline files. They are predefined. What to do?
If ALL the lines (on the call stack window) are external to your project (very strange, becouse this means that your program it is not running ) then you can run the app 'step by step' (F10, or 'step in' F11, in debug mode) the program to find out what function cause the crash.
But I think you have to look better the call stack: 99.9% the error is in your code
I tried step by step execution also(by pressing F10). Yellow Arrow moves to some of the system file like free.c,dbgheap.c,stdenv.c,crtlib.c,appui3.cpp and finally to disassembly.
If I continue this step by step execution(F10) from disassembly, once all the
lines are completed the Yellow marker moves to the file where it initially started(i.e this file is also not my file. It is system file only). If I execute step by step(like you said), the window did not open. But usually when run I run the program in debug or release mode, a window will open.
We can do all the operations defined(like loading an image file, moving or rotating an object, setting the visiblity of an object on or off). If I close the window using the cross mark on the top left corner, then only that exception occurs. If terminate the excecution using stop button in the tool bar no exception is thrown.
You need to pause the application one second before the crash...and then use debug tool like F10 or F11 to understand why it crashes. And do this, of course, before that the program exit from your code and goes to external dll(s).
You said that the exception comes when you close the application using the cross on the top right of the window....USE THIS INFO! Go to OnClose() (put there a brakpoint) and run the application step by step F10, F11.
Another thing: pressing the stop button in the VS toolbar will terminate the DEBUG mode, and it destroy the application, so no exception can occuors, beaouse NO CODE will run.
It can be defined where, even in a .myhdrfile if you really wanted to do so. The common practice is to put prototypes in .H files. The signature of the function usually has to be encountered, either as a prototype or as the actual implementation, before the function is actually used in code.
-=- James Please rate this message - let me know if I helped or not!<HR>If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
Last Visit: 11-Aug-20 21:43 Last Update: 11-Aug-20 21:43