|
9ine wrote: how can we handle this in one &operator() and class
Short of using a template, I do not know of a way. If you added another operator[] to the class, the compiler will complain because the formal parameter list between the two would be identical.
Now if you wouldn't mind replacing operator[] with an actual method (e.g., getChar() , getFloat() ), you could get this to work.
Templates are not as difficult as you might think. Consider:
template <class T> class vec
{
public:
vec()
{
data = new T[5];
}
~vec()
{
delete [] data;
data = NULL;
}
T &operator[]( const int nIndex )
{
return data[nIndex];
}
private:
T *data;
};
...
vec<char> c;
c[0] = 'z';
char q = c[0];
vec<float> f;
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
-- modified at 12:31 Thursday 23rd February, 2006
|
|
|
|
|
--------------------------------------------
vec<char> c;
c[0] = 'z';
char q = c[0];
vec<float> f;
--------------------------------------------
I need to code this situation:
long double lA;
vec<char> c;
vec<short> s;
lA = c[0]; //casted from char to long double in operator
lA += 5.0;
c[0] = lA; //casted from long double to char in operator
lA = s[0]; //casted from short to long double in operator
lA += 10.0;
s[0] = lA; //casted from long double to short in operator
//same for vec<float>,vec<double>
The value outside the vec class (that is extracted from it) is always the same type long double but when we save it back it must be converted to class type (char,short,...)
9ine
-- modified at 5:00 Friday 24th February, 2006
|
|
|
|
|
9ine wrote: The value outside the vec class (that is extracted from it) is always the same type long double but when we save it back it must be converted to class type (char,short,...)
Why? The largest value you'll be able to store (in a char ) from the long double is 128. Is this acceptable?
Perhas you should explain in detail exactly what your goal is. Then we might be able to offer a more viable solution.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
the deal is about ecg data. This is saved as ADC units with presicion 8,16 bits and if we convert it to long double lu[x] = c[x]/UmV and back after calculations (which retain its original range) c[x] = UmV*lu[x].
Keeping it in its original units will save a lot of memory.
It's a pity there is no overloading on return value, may be this a drawback in C++.
9ine
|
|
|
|
|
9ine wrote: ...if we convert it to long double lu[x] = c[x]/UmV and back after calculations (which retain its original range) c[x] = UmV*lu[x].
I'm not sure I follow you. If you have 12.34 stored in some long double variable, assigning that to a char variable will result in only the value 12 being stored, effectively losing the .34. Is that an issue to be concerned with?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
that is simple quantizing issue. If our ADC data get -128 127 range say over 1mV range then 127 will be 1.0 long double, the formula in that case is ADCval/127 and we get long double values -1.0 1.0 performing computation on them and converting them back to char multipluing by 127, 0.5 long double will be 0.5*127 char, The value higher than 1.0 will be saturated to 1.0
This simple as we can operate on RGB in OpenGL either int 0-255 or float 0.0-1.0
9ine
|
|
|
|
|
9ine wrote: how can we handle this in one &operator() and class
You can't, a C++ is (on purpose) unable to overload functions based on their return value.
You can only overload based on parameters.
So you are forced to rethink your design.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
-- modified at 5:20 Friday 24th February, 2006
|
|
|
|
|
I wanted to get code for vector class as small as possible, as modification of the lot of other code will depend on it. Last resort in this situation will be set/get methods, which is much awkward compared to a=v(x); v(x)=a;
9ine
|
|
|
|
|
9ine wrote: a=v(x); v(x)=a;
You can have this. Easy.
What you can't have is C++ selecting the correct overload based on the type of the return value that fits your assignment target.
That would be asking a little too much, as it would either be quite fuzzy or stop C++ from doing implicit casts.
And that would break compatibility to C-code and annoy me.;P
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
How about using void pointers?
void * m_Data;
void * operator[]( const int nIndex )
{
return m_Data+(sizeof (WHATEVER WE ARE CURRENTLY USING)*nIndex);
}
a = (double)*(vec[0]);
or
a = (char)*(vec[0]);
William
|
|
|
|
|
Engberts wrote: void pointers
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
I want to put a process in the startup folder so it can run in the background. (No console) Does anybody know how to make it run in the background.
Kelvin Chikomo
|
|
|
|
|
|
Thanks dude, i wil just create a process terminates on its own , this same process will create the proper process in the background.
Kelvin Chikomo
|
|
|
|
|
theprinc wrote: ...run in the background.
This is Unix terminology. Windows is a multitasking OS, so there is no concept of a processing running in the background or in the foreground. If a process is running, it is running, period.
Now, a process with no UI is a totally different matter.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
|
|
|
|
|
I have searched the world for a solution to format a CString value of the format "longdate" to "shortdate".
"YYYY-MM-DD hh:ss" to "YYYY-MM-DD".
I'm not using .net.
It should be simple, but not for me...
/LK
|
|
|
|
|
|
Yes thanks!
I found a solution:
COleDateTime dt;
CString theDate=pProject->getProjectCompletionDate();
dt.ParseDateTime(theDate);
if (dt.GetStatus()==COleDateTime::valid)
theDate=dt.Format(VAR_DATEVALUEONLY);
else
theDate="";
|
|
|
|
|
Well, if the format is fixed, you can simply truncate the string at the space between the day digits and the hour digits.
CString sTD = _T( "2006-01-02 12:34" );
sTD.Delete( 10 ); Peace!
-=- James 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! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
How to create folders befor uploading files on the server using wininet API
or WinHTTP
i know FTP provides that, but overall i want a secure channel and i want create folders from client to server.
as i can find SFTP is not a well known thing,and i don't want to use that
waiting for reply upload..........
------------------------------
Its not the fall that kills you; it's the
sudden stop at the end.
|
|
|
|
|
Hi,
my program is used to submit values to asp page using post method. but the submitted values are received on the server. my script in given below. any one help me out.
pServer = session.GetHttpConnection(CStrDomain,nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,CStrSuburl,Referer,1,NULL,"HTTP/1.0",dwHttpRequestFlags);
pFile->AddRequestHeaders(szHeaders);
pFile->SendRequest(NULL,0,(void*)(const char*)CStrTempQueryString.GetBuffer(CStrTempQueryString.GetLength()) ,CStrTempQueryString.GetLength());
urgent. Thanks in Advance.
Have A Nice Day!
Murali.M
Have A Nice Day!
Murali.M
|
|
|
|
|
Hi ,
We all know windows system supports left mouse button drag and drop operation.
And we still can let our own application to support drag and drop operation.
My issue is can we hook system's Drag&drop operation when user drag&drop files between two system folders.
For example,User does drag&drop operation in two system owner folder(eg, C: source folder and D: target folder). Can we get draged data information when mouse is moveing in C folder region.
Any advice is welcome!
Thanks,
Welli
|
|
|
|
|
Hi all !
I'm having a problem. I want to write to xml file with format
<Level_1>
<Level_2>
<level_3>
<level_4> value </level_4>
</level_3>
</Level_2>
</Level_1>
The problem that DataSet object have normal 3 levels(dataset, datatable, datarow). I used method DataSet.WriteXML() but not expected.
Please help me and reply !
Many Thanks !
PS: Don't write by normal way ( using XmlTextWriter object)
I'm developing with VC++.Net 2003 language.
SweetHeart
-- modified at 3:54 Thursday 23rd February, 2006
|
|
|
|
|
Can you edit your message and check the box that says "Do not treat <'s as HTML tags" otherwise we can't see your XML.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I have used following technique to make dialog invisible
at startup; which i have taken from Nishant Sivakumar's
article "Some handy dialog box tricks, tips and
workarounds".
void CTest_deleteDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
if(!visible)
lpwndpos->flags &= ~SWP_SHOWWINDOW;
CDialog::OnWindowPosChanging(lpwndpos);
}
The problem is how can i terminate cleanly an invisible dialog application
I have tried following;
1. Sending postmessage(wm_close) to dialog but it
donot work; probably because the dialog is invisible.
2. OnOK() is also not working.
3. Showing the dialog and immediately and sending close message produces
a splash therefore avoided.
3. exit(1) works fine but I am not sure that it teminates
application cleanly or not so, I want to avoid this.
4. calling the Exit instance of main application even donot work!
((CMYApp*)AfxGetApp())->ExitInstance();
this should work because I am calling application object exit? but it wont?
I am looking for a clean solution to terminate a hidden dialog application.
Thanks in advance.
|
|
|
|