|
Converting a class I have into a class template
so that I can utilize it for various data types.
I've never used templates before, and am trying
to sort a few things out.
In the class I currently hold data in an array of
doubles by declaring a pointer to the data.
<br />
double* m_pdData;<br />
and then initialize using the operator new . So that
<br />
m_pdData = new[double dSize];<br />
I'm not entirely clear on how to declare these items
in a templated version of the class.
Would their equivalents be:
<br />
T* m_pdData;<br />
and
<br />
m_pdData = new[T dSize];<br />
or is there a little bit more to it??
Also, what is the notation convention?
ie: for a member function that's a pointer
to type double we prefix with m_pd
for a template what would be the equivalent...
m_p???
TIA.
John Theal
Physicist/Mathematical Programmer
Digital Immersion Software Corporation
Got CAD?
http://www.presenter3d.com[^]
http://www.merlin3d.com[^]
|
|
|
|
|
Change "m_pdData = new[T dSize];" to:
m_pdData = new T[dSize];
|
|
|
|
|
|
You can use your templated type anywhere you would use a normal type although you have to qualify it with the appropriate template parameters e.g.
<br />
T<int>* pData = new T<int>[ 100 ] ; <br />
I usually create a typedef to make things more readable:
<br />
typedef T<int> MyIntClass ; <br />
MyIntClass* pData = new MyIntClass[ 100 ] ;<br />
Likewise for pointers to member functions although there are pitfalls: you can't take the address of a function of the template class, you can only take the address of a function of an *instantiated* template class i.e. you can't do &T::fn, only &T<int>::fn.
WRT to variable naming, it's time to drop the Hungarian, it just doesn't work with OO. I just use m for member variables, p for pointers, g for globals and r for references. Anything else will drive you nuts!
"Sucks less" isn't progress - Kent Beck [^]
Awasu 1.1.2 [^]: A free RSS reader with support for Code Project.
|
|
|
|
|
|
Hey Friends
I am using MFC Doc/View architecture for printing some lines.
I want to display a Few Lines on the View and then take the printout.
I am trying to use MM_LOENGLISH map mode but could not get things done.
Can someone Please Give me a 10cm Line on Printer.
Also I wish to find out the paper size in cm or may be in pixel.
Trying to get through OnPreparePrinting 's PrintInfo but i get some -ve values of the rectangle
Plz Help
|
|
|
|
|
Here you go:
-------------------
-----------------------
Best not to ask too many serious questions Saturday night.
J.
----------------------------
|
|
|
|
|
I remembered that after i had posted the question.
|
|
|
|
|
I have a CFormView. If I remove the menu, then it will look
alot more like a CDialog, but yet retain alot of built in
MFC functionality. Is there anyway to remove the menu? I
can't just delete it because I get an error.
|
|
|
|
|
The menu is part of the CDocTemplate, at least in the document / view architecture. The CFormView can handle messages from the menu, but it is not necessary to it. The error is most likely the CDocTemplate complaining that it can't find the IDR_MAINFRAME Menu, if you deleted it. YOu probly will have to set the style of the MainFrame window to exclude the menu, and replace IDR_MAINFRAME with NULL.
J.
----------------------------
|
|
|
|
|
I receive the error "Failed to create empty document".
How can I set the style of the MainFrame window to exclude the menu
and replace IDR_MAINFRAME with NULL? By chance, do you have any
code that you can share?
Please, any response you can give me will be greatly appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
It is in your App clas. Look for the class that says CSomeApp, with Some replaced with the name you chose. If it is a SDI it looks like
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME // Change this to NULL
RUNTIME_CLASS(CFlightTracerDoc),
.
.
.
J.
----------------------------
|
|
|
|
|
You must also override PreCreateWindow in CMainFrame and insert the following code
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.hMenu = NULL; // Insert this code
.
.
.
J.
----------------------------
|
|
|
|
|
I have some code that I get the following error when
Run-Time Check Failure #2 - Stack around the variable 'rasterizer' was corrupted. This only happens in debug. And it ONLY happens if i turn on the Basic Runtime Checks setting for C++ has Stack frames turned on (/RTCs).
The rasterizer variable is a stack based template class from the AGG[^] graphics lib, which makes HEAVY use of template classes.
The code in question is in the else branch of an if statement, and at runtime is NOT getting executed, and since the variable is within the scope of the else block, it's not getting instantiated either.
If I comment the chunk out, then everything is hunk dory. If I use the default settings for Basic Runtime Checks then everything is OK as well.
Is this something to be concerned about? Whoudl I just use the default settings? Is this some new behaviour introduced into the VC7 C++ compiler?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
In a debug build, the compiler generates stack frame setup code to account for every variable separately. In a release build, the optimiser works out which variables have overlapping lifetimes and allocates only enough space for the variables that can't share the same memory locations.
If you enable /RTCs, the compiler adds additional padding around any variables that it thinks could be subject to buffer overrun errors, and fills it with particular values. At the end of the function, the generated code checks to see if the values have been modified - if they have, it generates the runtime check dialog you saw.
You should leave this option turned on, and fix the buffer overflow that it detected. It could easily mean that a different variable had the overflow. To detect which variable, generate a listing file (/FAs or /FAcs) and examine the resulting .asm or .cod file to see where the compiler allocated each local variable. Alternatively you could inspect the addresses in the debugger.
If you can work out which area of memory is being corrupted, you can use the debugger's Data Breakpoint facility to discover which piece of code is writing to that address.
|
|
|
|
|
Help!
I am using Winexec to call another C++ compiled program. All at once the button won't execute the program, but I CAN start the program by double clicking it's icon.
Code I'm using:
WinExec("MyProg",SW_SHOW);
If I double click the MyProg icon, it runs fine!
The button used to work, but just quit. I am flummoxed
Any help greatly appreciated!
Richard
|
|
|
|
|
Try specifying the full filespec path, eg:
WinExec (_T("C:\Dir\MyProg.exe"), SW_SHOW);
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
why can't u guys just read the documentation!?
Don't try it, just do it!
|
|
|
|
|
WinEXec is deprecated - it may be removed from Windows at some point in the future. It's only for backwards compatibility with 16-bit Windows.
You should consider using ShellExecute or CreateProcess instead. CreateProcess is normally preferred if you know that the file is an executable.
In either case, the executable found (and even if it's found) depends on the executable search path. See CreateProcess in MSDN[^] for more details.
|
|
|
|
|
Got a weird problem here... I have some list controls that are drag sources. I use LVM_CREATEDRAGIMAGE to get the images, however this returns a solid black rectangle if the list has a background image (as set by LVM_SETBKIMAGE ). The drag image is perfect for lists that do not have a background image.
WTF? Any ideas?
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
CP SearchBar v2.0.2 released
|
|
|
|
|
I've never used those message so I may be out on a limb here
Aren';t the drag image fro the listview partially (or wholly) dependant on how you set up the image list that you associated with the listview? Maybe the image list doesn't have the right settings for tranparent images? Just guessing
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
|
|
If anybody know link for design specification/architecture for creating Plug-in.
I am not using MFC. Only C++ Win32 SDK.
|
|
|
|
|
The Visual Component Framework[^] makes plug-ins really easy to write.
The whole framework comes in 3 libs and for your purposes you'd probably only want the FoundationKit. It allows you to define RTTI extensions to your classes, register them with a global ClassRegistry, and then be able to do all sort of dynamic queries of object instances. For plugins, you'll conceivably want to create stuff on the fly, and you can also do this, it has support for createing C++ clases from the class name or the unique ID you give the class. If your interested in this feel free to email me at ddiego@users.sourceforge.net. You can also reach me on irc at irc.freenode.net #vcf
Hope this helps
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|