|
std::list is not a "random access" sequence (i.e. cannot use a random access iterator).
Watched code never compiles.
|
|
|
|
|
As Richard and the others have said, use vector if you can. If you really really really must have at-like functionality you can use std::advance to do it.
Cheers,
Ash
|
|
|
|
|
Thanks a lot....
It is working......
|
|
|
|
|
What about:
template <typename T> class mylist: public list<T>
{
public:
T & at(int n)
{
int i;
list::iterator it= this->begin();
i = 0;
while (it != this->end())
{
if ( i==n ) return *it;
i++; it++;
}
throw( out_of_range("out of mylist range"));
}
};
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]
|
|
|
|
|
|
depending on how the at() is used you can shortcut operations by holding the current iterator around as long as add/delete/insert operations have not been done. Using the difference between last at() and current at() you can move up or down the list. It takes some work, but if you are doing big searches you wouldn't always want to start at the beginning unless the new at() command is closer to the start or the end. and if you do add/delete/insert, just invalidate the iterator, and start over as you have done.
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
Clever.
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]
|
|
|
|
|
CPallini wrote: Clever.
naw... comes from using skiplists, which made me think that wouldn't be a bad method here if there aren't many add-deletes, skip-lists let you jump around lists rapidly.
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
Well, skiplists (I didn't know about) are clever, at lest...
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]
|
|
|
|
|
If you use at() often you might consider something like a skip-list:
http://www.codersource.net/microsoft-net/c-advanced/skip-list-a-simpler-alternative-to-binary-trees.aspx[^]
Skip lists would allow you to skip sequentially starting from the beginning on ever at() command.
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
Hi,
How to change selection color of CEdit control?
Can I put image on selection instead of color?
|
|
|
|
|
Hi,
If you handle the WM_CTLCOLOR message in your edit control you can change the characteristics of the display context used to draw the text, so you can change the colour of the text and, by extension, the inverse video colours used for selected text.
To the best of my knowledge if you want to overlay an image then you'd have to overide or replace the standard drawing code - which would be a lot harder.
Cheers,
Ash
|
|
|
|
|
Can you guide me with some sample code or link...
|
|
|
|
|
|
can we use class1 in class2 without include the class1.h file???
|
|
|
|
|
Yes, for example if class1 and class2 are both declared in the same file and class1 is declared before class2. Othwrwise, it depends on what you mean by "use". Next time try a bit more descriptive subject if you post a question, please, "hi" just won't do...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers are evil, EVIL i tell you!! <
|
|
|
|
|
Hi back,
You can refer to a class that hasn't been defined (in simple terms not had it's .h included) but you can't do anything that requires the compiler to know the size or composition of the class. So, without the .h file you can...
- declare a reference to an object of the class
- declare a pointer to an object of the class
- assign pointer to objects of the class
You'd be pushed to say that this lot is "using" the class though. What you can't do...
- call member functions of the class
- do any sort of RTTI (run time type information)
- get the size of the class which in turn means you can't create objects of the class
Cheers,
Ash
|
|
|
|
|
|
Hello,
I have a small DLL written in C++ that exports 4 functions. I call this DLL from my C# application and can call all these functions without any problem.
I want to arrange for a DLL function to be called exactly once (sort of like a static constructor for the DLL). What is the best way to do something like this?
Thanks,
Keith
|
|
|
|
|
What do you mean by "called exactly once"?
You wanna prevent from "calling the dll function for a second time", or just make no
effect when "calling the dll function for a second time"?
|
|
|
|
|
You could try sticking the code you want executed exactly once in the DllMain for the DLL. Unfortunately there are some restrictions as to what can go in DllMain - don't do anything that might trigger another DLL load or it could go horribly wrong.
Another option is to create an initialisation function and either just call it once or use a language feature of C# to make sure it's only called once. I don't know C# and it's idioms enough to suggest a relevant feature. You can make sure your initialisation function is only called once in the DLL using something like:
extern "C"
bool FOO_EXPORT initialise_foo_lib()
try
{
static bool initialised = false;
if( !initialised )
{
initialised = true;
}
return initialised;
}
catch( std::exception & )
{
return false;
}
Cheers,
Ash
|
|
|
|
|
Hi,
would anyone if I can get Crect structure/CLass from the current selection
I would like to create Rgn to paint the Background of a bitmap displayed on my Richeditctrl
thankx
|
|
|
|
|
I'm assuming you're using MFC.
The CRichEditCtrl class has a method called GetSel which returns the index to the starting and ending characters in the selection.
Now use CRichEditCtrl::PosFromChar on the starting and ending characters to get their X and Y positions.
You can now build a CRect using the 2 CPoint structures returned.
|
|
|
|
|
Thankx
To create a region then to fill the background, I am going to try it, but I think I'll have to do ClienttoScreen afterwards since the regions is a area of the display
|
|
|
|
|