|
Friends,
Consider the following template function inside a namespace CP:
namespace CP
{
template < class T >
T TemplateFunction(int value)
{
cout<< _T("I am in template function") << endl;
return value*2;
}
}
A function inside a namespace can be accessed in three different ways. So i like to access this function from the main program in three different ways:
1)
using namespace CP;
int main(int argc, char* argv[])
{
int m = TemplateFunction< int >(44);
return 0;
}
As such the program is working normal and not giving me any errors.
2)
int main(int argc, char* argv[])
{
int m = CP::TemplateFunction< int >(44);
return 0;
}
In this case the programs works normally as expected.
3) Here is a problem:
using CP::TemplateFunction;
int main(int argc, char* argv[])
{
int m = TemplateFunction< int >(44);
return 0;
}
In this third case the compiler is giving me the following error:
C:\test.cpp(32) : error C2062: type 'int' unexpected
Can anyone tell me about the problem in third case.
|
|
|
|
|
Compiles fine in VS.NET 2K3. What compiler are you using?
- Mike
|
|
|
|
|
Jahangir Jamshed wrote:
Can anyone tell me about the problem in third case.
Screwed up compiler. I'm assuming you're using VC6?
--
Ofra Haza: R.I.P
|
|
|
|
|
I've got a read-only Edit Box in my dialog which is used to display diagnostic information so it's constantly being written. As I add to the string in the box, I call UpdateData(FALSE) on the dialog to refresh the view.
The problem is that, when the dialog refreshes, the scrollbar of the Edit Box always jumps back to the beginning. I can follow the UpdateData() call with a call to the LineScroll() function of the Edit Box but I still get a momentary flicker as the scroll changes.
Is there a way to make the scrollbar of the Edit Box always go the bottom-most position when updating?
|
|
|
|
|
Instead of a CEdit use a CListBox::AddString for logging provided formatting is not that important for your app. It automatically scrolls to the last item without flickering
Bunburry
|
|
|
|
|
I considered that but I would prefer to use CEdit so that the user can highlight and copy text to the clipboard.
|
|
|
|
|
If you update all the contents of your CEdit (even the old shown text) every time you just wanna append something, the flickering is understandable.
Try instead letting the old text in place and set the cursor to the end of your Editbox with SetSel (enabling scrolling) and then replace the cursor with your text to be appended using ReplaceSel
Bunburry
|
|
|
|
|
Are there any special cases where we can only use pointers and not references or vice versa?
|
|
|
|
|
Well here is one where you can only use pointers.
int* pInt=new int[10];
John
|
|
|
|
|
Well, you could do:
int& rInt = *new int[10]; but then you'd have to
delete[] &rInt; which tends to confuse people. It's not generally recommended to use a reference to refer to dynamically-allocated store in this way.
A reference can only be bound once, at construction time. If you know that you don't wish to change which object is referenced, use a reference. If you might need to change which object is pointed to (i.e. change the value of the pointer) use a pointer.
If the value could be NULL , use a pointer. Most developers expect that a reference always references an object and don't check it for NULL - not to mention that the only way to do this is to take the address of the reference. The type may have overloaded operator& , and you might not get the actual address of the object.
I normally use references in two places: to mark 'required pass by reference' in a function declaration, and to rename an object with a long name to a shorter name. For optional pass by reference, or where the API is already dealing in pointers, I use a pointer.
|
|
|
|
|
Thanks for the info. I never knew you could do that.
John
|
|
|
|
|
I need some articles, tutorials, websites, etc... to learn file management well, I would be very thankful if anyone helped.
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
"File management" is quite a broad topic. What kinds of files are you trying to manage?
- Mike
|
|
|
|
|
Text Files
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
Have you even looked?
"Sucks less" isn't progress - Kent Beck [^]
Awasu 1.1.3 [^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Hmm.. What does one do when one manages text files?
--
Ofra Haza: R.I.P
|
|
|
|
|
Yes but nothing i found came close to my problem, I'm thinking that I'm just a bad looker, I tried google and... you get the picture
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
Not wanting to sound preachy but one of the most important things these days is not necessarily how much you stuff know but the ability to find it when you need it.
Whenever I'm looking for stuff like this, I always look for "XXX tutorial" and it usually gets me pretty good hits. So Google for "file management tutorial", "file I/O tutorial", "managing files tutorial" and you should find something!
HTH
"Sucks less" isn't progress - Kent Beck [^]
Awasu 1.1.3 [^]: A free RSS reader with support for Code Project.
|
|
|
|
|
what do u mean with manage files ?? like doing what ?
|
|
|
|
|
like finding the end of a file and then deleting upwards until a certain point, certain character
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
You cannot delete certain bytes from a file partially but you can copy the required bytes to another file.
Search in MSDN for using CFile
Bunburry
|
|
|
|
|
I posted an article up today with smart tic tac toe, I should have known better, I got alot of bad emails and everything, I took it down and decided I will have to find some spare time if possible in the near future of completion of my project, I will eventually post it up and still use The Code Project as a very well respected resource, it's just that I am under a lot of stress right now and I have a lot of problems with my project, one of which is time. Though I know the layout of the program, I don't exactly know how to manage files that well. Sorry again, don't get mad at me.
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
does anyone has an example of using MSXML4 DOM parser..?
I know there's one here that uses some dll..but I actually need something like this: but this one has it's issues...
it is good, but there is something wrong, plus i would need msxml 4 version if it...he is using here msxml3:
but that's excactly what i need: (except version msxml4 :
http://www.codeguru.com/data-misc/DdEdE.html
thank you.
_ra
|
|
|
|
|
I am kinda new again to Visual C++ it has been 6 and a half years. I have started a new workspace, it compiles right and all, I have added alot of features to it so far to get the program running the way I want it. Unfortunatly I am having trouble changing something easy now. I haven't yet messed with the doc.cpp or doc.h or the view.cpp or veiw.h I told it (when I created the MFC Wizzard) to allow for server stuff. Well I want to change the document to a text document. What part of the doc.cpp and doc.h do I have to change to get it to be a text document? and so that it becomes active when I click it? My program allows for multiple files open at once, and some of them will have different file extentions.
LOSTTWARE.com
|
|
|
|
|
Is there any way to programatically change a theme on Windows XP??? I'm talking about a system-wide change, like what can be done in "Display Properties > Themes".
After spending hours on this, I've come to the conclusion that Microsoft has not documented any of the information required for 3rd party developers to do this. Is that correct??? If so, that seems crazy. Why is Microsoft the only one with access to such an obvious feature in Windows? After all -- it's a part of the Desktop Properties dialog and there are ways to change everything else (wallpaper, screen savers, desktop icons, etc). How can there be no way to automatically change a theme?
The closest I could come is manually updating the registry, and then logging off and back on. However that is not acceptable, unless there is some way to make the Windows desktop completely refresh itself (thus reload the Theme) without requiring a logoff. ???
I also tried playing with virtual desktops, manually broadcasting WM_THEMECHANGING, and even took a look at all of the text and function names in desk.cpl to see if I could get a clue as to what it is doing -- but didn't get anywhere.
Does anyone have any ideas at all???
|
|
|
|