|
Stuart Dootson wrote: Na - I just remember lotsa crap that I can regurgitate (or find with Google) on demand
Isn't that what being a good programmer is all about? I doubt many of us know everything, we just have a clue where to look, or the search terms.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Iain Clarke wrote: Isn't that what being a good programmer is all about?
A self-reliant programmer, certainly. The trick is remembering that things actually exist, so you know to look for a solution rather than try to re-invent the wheel.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
i use VS2005
today i programe a .cpp File to learn "Template"
the source code is:
<br />
#include<iostream><br />
using namespace std;<br />
<br />
template<typename Type><br />
<br />
Type min(Type a,Type b)<br />
{<br />
return a<b?a:b;<br />
}<br />
<br />
int main()<br />
{<br />
int a = 0, b = 1, c = 3;<br />
<br />
c = min<int>(a,b);<br />
<br />
cout<<c;<br />
}<br />
but when i run the result is show wrong can somebode help me
|
|
|
|
|
jeansea wrote: but when i run the result is show wrong can somebode help me
What is the result you have and what did you expect ?
|
|
|
|
|
compiler error the message is
error C2668: “min”:
|
|
|
|
|
jeansea wrote: error C2668: “min”:
Not very usefull reply...
Anyway, you don't have the error when you run but when you compile then ? That's something completely different.
The problem probably comes from the fact that min already exists (I think). Try using another name or putting the function in a specific namespace.
|
|
|
|
|
oh....yes
i think you are right when i using another name is can run and no error
thanks
|
|
|
|
|
jeansea wrote: compiler error the message is
error C2668: “min”:
Let's be more accurate - that's part of the message...this is the message I get from your code:
error C2668: 'min' : ambiguous call to overloaded function
a.cpp(6): could be 'Type min<int>(Type,Type)'
with
[
Type=int
]
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\xutility(3397): or 'const _Ty &std::min<int>(const _Ty &,const _Ty &)'
with
[
_Ty=int
]
while trying to match the argument list '(int, int)'
It helps when a) programming, or b) asking questions about programming, to get all the details correct and in place...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
i want to put all detail messages but i the message show in chinese...
i know to put all error message next thank for tips
|
|
|
|
|
jeansea wrote: i want to put all detail messages but i the message show in chinese...
OK - I'll let you off - my Chinese reading skills are sadly lacking
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
jeansea wrote: but when i run the result is show wrong can somebode help me
Cédric Moonen wrote: What is the result you have and what did you expect ?
jeansea wrote:
compiler error the message is
error C2668: “min”:
TOO FUNNY!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
jeansea wrote: when i run the result is show wrong
When you run what?
As I expected, you get a compiler error when you try and compile that code, because the standard library already defines a template min function. You need to specify which min you want, by specifying that you want the 'no namespace' version (for that is yours) like this - oh, and you don't need to specify template parameters for functions if the function argument's types unambiguously specify the template parameters:
c = ::min(a, b);
Oh - and using namespace std; is bad form - use a using declaration instead. In your case, that would be 'using std::cout '. Those changes leave your program like this:
#include<iostream>
using std::cout;
template<typename Type>
Type min(Type a,Type b)
{
return a<b?a:b;
}
int main()
{
int a = 0, b = 1, c = 3;
c = ::min(a,b);
cout<<c;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Would you stop already? Whenever I want to answer some question here, your answer is already posted.
|
|
|
|
|
Sorry sir, I'll stop now
Actually, I'm going to be off t'Internet from Thursday till Monday, so if you could cover for me, that'd be good
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
So your creator has decided to turn off all the bots for a while? :P
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
Just for a short time while we upgrade them to a cluster of Mac Pros rather than Mac Minis
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
Welcome in the THHB [^], [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Welcome in the THHB [^], [^]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I tried using shared pointer in VS 2008 trial edition(Team suite) in a Win32 application,
#include "stdafx.h"
#include <memory>
int _tmain(int argc, _TCHAR* argv[])
{
std::tr1::hexfloat //Only this comes in tr1 namesspace
std::tr1::shared_ptr sharedPtr;
//std::tr1:: error C2039: 'shared_ptr' : is not a member of 'std::tr1'
return 0;
}
It’s supporting auto_ptr but not shared_ptr. Is the problem in my coding or because of trial version.
VIBIN
"Fool's run away,where angle's fear to tread"
|
|
|
|
|
Could be the trial version - I seem to remember tr1 only got added to VS2008 in service pack 1 or with the Visual C++ 2008 Feature Pack[^].
Anyway - std::tr1::shared_ptr works fine for me on VS2008 with service pack 1 installed.
PS - you'll need to tell shared_ptr (as a template parameter) what type it's pointing at!!!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello I want to read from com port1, and I used API
if (WaitCommEvent(hSerial, &dwCommEvent,NULL))
{
if (dwCommEvent & EV_RXCHAR)
{
DWORD dwNumberBytesRead;
if(ReadFile(hSerial, chRead, sizeof(chRead),&dwNumberBytesRead,&osReader))
I have got an extra Thread to read com port but if data is not send to port my program hangs up.
Is there any way to check if input buffer is changed and then ReadFile instead waiting for
WaitCommEvent ??, or if there is some other ways?
Thanks in advace
|
|
|
|
|
komofilms77 wrote: ...or if there is some other ways?
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
When I've programmed serial ports, I've not used WaitCommEvent - I've set a timeout period with SetCommTimeouts [^] and just used ReadFile . If the serial port receives data or times out, then ReadFile returns successfully and will tell you how many bytes it received (0 probably indicates a timeout).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I want to convert a cstring into LPBYTE but each time i convert it only first character get stored in the LPBYTE and rest of the string is truncated.
Thanks
amit
|
|
|
|