|
No, it's not the same purpose.
I really need the template for the member function, not for the class.
It's only for one function, not for the whole class
|
|
|
|
|
class foo
{
template <class T> void F (T var) { cout << var; }
};
void main()
{
bool B = true;
foo Foo;
Foo.F(B);
}
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Yep, but it's not what I really wanna do
And in this case I prefer doing:
template < class T > void F (T *var) { ... }
and:
Foo.F((bool*)0);
Doing this way, the T object is not construct.
Nonetheless, it's a bit dodgie...
|
|
|
|
|
This is kinda difficult.. I used the following code piece:
class Foo
{
public:
template<typename T> void F() { T var; }
};<DIV>
void main()
{
Foo tmp;
tmp.F<bool>();
} This piece of code compiles properly, but issues a warning about an unreferenced local variable var which is what it should do as well.
Also, the first code piece you posted also compiles properly, but issues the same warning. I am using Visual Studio .NET 2003, so perhaps it's a compiler bug ?
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I guess it's a compiler issue.. I'm using VC6 sp5
I send this code to one on my friend which got exactly the same problem.
Worst: if you try to change the member function into a static member function, the compiler crashes.
|
|
|
|
|
Kandjar wrote:
template< class T > void F() { T t; }
That is a known problem in VC 6, that arises when the template parameter isn't present in the prototype. The common workaround is:
template< class T > void F(T* unused=NULL) { ... }
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Martin Kolberg, head of the local animal committee in Telemark, warns people to beware of drunken moose.
If my rhyme was a drug, I'd sell it by the gram.
|
|
|
|
|
I tried, but I'm still unable to do:
tmp.F< bool >();
Am I obliged to do
tmp.F((bool*)0);
to be able to use it?
|
|
|
|
|
I would like my output to be 4 hex digits.
0000 0001 0002 ... 000a 000b ... 0015
I am using the following loop to do this:
<br />
for (int i = 0; i <= 21; i++)<br />
{<br />
cout << setw(5) << hex << i << endl;<br />
}
It currently displays as
0 1 ... a b ... 15
Any help would be appreciated.
S.W.
|
|
|
|
|
printf( "%04x", 255 );
output will be
00FF
so what you want is probably
for( int i = 0; i <= 21; i++ )
{
printf( "%04x\n", i );
}
|
|
|
|
|
Thanks Archer,
Would you mind breaking the statement down for me or maybe you know of a link that would explain it to me. I appreciate your time.
|
|
|
|
|
Keep in mind that cout and printf() are not the same thing. The former is C++ while the later is C.
For a purely C++ solution, you simply need:
cout.fill('0');
cout << setw(5) << hex << i << endl;
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Personally i prefer to use printf() over cout<<
but thats a matter of personal opinion
i really dont know how to explain printf()
you can look at microsofts description if it makes any sense
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_printf.2c_.wprintf.asp
but what i can do is give you some examples and maby you can pick up on it (note i figured it out from examples)
printf( "This is a %s", "test" );
output: This is a test
printf( "This is 282 in lowercase hex %x", 282 );
output: This is 282 in lowercase hex 11a
printf( "This is 282 in uppercase hex %X", 282 );
output: This is 282 in uppercase hex 11A
printf( "I was born %02d/%02d/%02d", 11, 28, 87 );
output: I was born 11/28/87
|
|
|
|
|
HICON hIcon;
LPBYTE lpBuffer;
hIcon=dlg.GetIconHandle();
lpBuffer=(LPBYTE)::GlobalLock(hIcon);
HANDLE hUpd=BeginUpdateResource("D:\\n.exe",0);
UpdateResource((HMODULE)hUpd,
RT_ICON,MAKEINTRESOURCE(1),
MAKELANGID(LANG_NEUTRAL,
SUBLANG_DEFAULT),
(LPBYTE)lpBuffer,
GlobalSize(hIcon));
EndUpdateResource(hUpd, FALSE);
GlobalUnlock(lpBuffer);
I'm using this code to take the icon from an exe and replace the icon in another exe, but it doesn't work. Every time lpBuffer is empty after GlobalLock. the hIcon handle is retrieved by ExtractIcon();
What am I doing wrong?
Please help!
|
|
|
|
|
I doubt you can do lpBuffer=(LPBYTE)::GlobalLock(hIcon); .
See this MSDN article[^] for more information on icons and resources. It links to a program written in C which has some code you can look at too.
Please note that the structs in the article are wrong. Look at the code in the linked project instead. I believe you will have to fill out an entire ICONDIR, as icons are stored that way (an icon can contain several images). Then the appropriate number of ICONDIRENTRYs and ICONIMAGEs. That's what's supposed to be inside the resource part.
But you are talking about replacing the icon in one exe from another one. I believe you can do the copy without too much work. Just grab a pointer to the icon resource in the source exe, and use it to update the icon entry in the other exe. I think that should work. The linked project has all the details. Good luck
--
Arigato gozaimashida!
|
|
|
|
|
Well this is my problem: How can I grab a pointer from the resource (HICON)??? I was trying to do just that by using GlobalLock().
Do you know any other way to do this???
|
|
|
|
|
Read the MSDN article. It'll tell you what you can do with an HICON (hint: GetIconInfo() and build resource data from that)
--
Arigato gozaimashida!
|
|
|
|
|
If I have the following:
struct Node
{
// various types
} *(*pNode)[7]; // ptr to a 2-dimensional array
===========================
In the ctor I have the following initialization procedure:
for(short i=0; i<7; ++i)
{
*(*(*pNode)+i) = NULL;
}
It doesn't work, and neither does various other efforts.
Later I want to do this:
**pNode = new Node;
(**pNode)->Lvl = 1;
etc.
==============================
If the array is not initialized, no object can be placed in it.
There is a reason why I DON'T want to define the pointer to the array as shown below (or something similar):
*pNode[5][7];
How can I initialized the array using the first example?
Thanks for any insight. I appreciate it.
William
Fortes in fide et opere!
|
|
|
|
|
*(*pNode)[7] is the same as :
Node* (*pNode)[7];
And reads as : a pointer to an array of 7 Node pointers.
Two pointers, two things need to be allocated.
1.
*(*pNode)[7] you have two * and an index [7]
*(*(*pNode)+i) you have three * and an index i
These don't match.
Instead use either :
*((*pNode)+i) = NULL;
or,
(*pNode)[i] = NULL;
2. for( ...
Before you can initialize pNode you have to allocate it. Remember pNode is a 'pointer ...'.
i.e.
pNode = (Node*(*)[7])calloc(7, sizeof(Node*));
Also, by using calloc you don't need to loop to initialize.
3. **pNode = new Node;
What are you trying to do ? pNode is a pointer to an array. Here you only ever access first element.
You likely want to use syntax from 1. i.e. (*pNode)[i] = new Node;
Might be able to help more if you explain the context of its use.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Thanks for responding. I appreciate it.
Yes, you are very correct that by my doing the following:
**pNode = new Node;
I am only accessing the first of 7 Nodes. But then notice the next statement:
(**pNode)->Lvl = 1;
in which I start filling in data to that first node (which happens to be my root node). Later on, through the use of the "for" statement I begin to fill in the rest of the array this way (as an example):
for(short i=1; i<limit; ++i)
for(short j=0; j<7; ++j)
{
(*(*pNode+i)+j)->Lvl = *(lvlData+j);
(*(*pNode+i)+j)->lvlNode = *(nodeData+j);
... etc.
}
=============================
Inside the Node structure, there is still a third array to which I assign data this way:
*((*(*pNode+i)+j)->nodesUp+k) = *(nodeCnt+k);
=============================
It was the initial allocating of memory to the "j" level of the array that was holding me back.
Thanks for the help. I appreciate it.
William
Fortes in fide et opere!
|
|
|
|
|
If you will kindly indulge me one more time, I forgot to mentioned that I'm using:
free(pNode);
to deallocate the memory. Is that OK, or should I do a 'delete' on the individual Nodes I dynamically created, BEFORE doing the 'free(pNode)'?
Thanks. I appreciate the use of your valuable time.
William
Fortes in fide et opere!
|
|
|
|
|
Hi,
1.) struct Node
{
// various types
} *(*pNode)[7];
this is not a ptr to a 2-dimensional array. This is an array of ptr to ptr.
To make it clearer you can rewrite it:
typedef Node **PtrPtrNode;
PtrPtrNode ppNode[7];
2.) initilalize it as follows:
for (int i = 0; i < 7; i++)
{
pNode[i] = new (Node*);
*(pNode[i]) = new Node[5];
}
3.) filling a node is done as follows:
Node* pNodeArray = NULL;
for (int i = 0; i < 7; i++)
{
pNodeArray = *(pNode[i]);
for (int j = 0; j < 5; j++)
{
pNodeArray[j].Lvl = 0;
}
}
4) releasing:
for (int i = 0; i < 7; i++)
{
delete [](*(pNode[i]));
delete pNode[i];
}
}
I didn't compile it but I hope it's 'error free'
Regards, Tomer
|
|
|
|
|
Confer Lippman's "C++ Primer", page 414 (about 3/4 down the page) under Section 8.4.3, and see his example of a two dimensional array of which I similarly used.
I can quote you my references, quote me yours.
William
Fortes in fide et opere!
|
|
|
|
|
Sorry,
I was wrong you were right
I was confused between *(*pNode)[7] and **pNode[7] which are two different things.
|
|
|
|
|
Hi,
is there a way to check an item when using InsertItem()? I'm trying to use SetCheck after InsertItem but it won't work!
How can I do that?
Thanks!
|
|
|
|
|
I have an MFC dialog based application containing several modeless dialogs.
A user has asked that one of the dialogs be multiple; i.e. the particular dialog displays data from an internal database and wants up to 5 instances of this dialog display showing various filtered views on he database.
So my question as I have all the code for managing the display dialog, can this dialog be made into an dialog array. Or are they another way extra instances of this dialog can be created.
Any suggestions for this unforeseen problem.
grahamfff
|
|
|
|