|
Hello, I basically want to make a function that will take in any interator and perform operations on it. For example, if I had the function: >mySort( iterator, iterator ) I would be able to pass in a std::vector iterator, a std::set iterator, a std::list or any iterator defined for a customized container, or any other STL container. Is this possible??
Mike - I love to program!
|
|
|
|
|
allenmpcx wrote:
Is this possible??
Yes, but it needs to be a template function, not a function. For examples, see standard algorithms[^].
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
-- modified at 21:47 Wednesday 28th September, 2005
|
|
|
|
|
These are all good, however when I try to take the ideas and implement them, I get errors, or they don't work correctly. Are there any examples that would do a simple sort using iterators only??
Mike - I love to program!
|
|
|
|
|
|
template< class Iter ><br />
void InsertionSort( Iter first, Iter last )<br />
{<br />
Iter step;<br />
Iter i;<br />
for( step = first; step < last; step++ )<br />
{<br />
Iter temp = first;<br />
for( i = step; i >= first; i = (i-first) )<br />
{<br />
if( (*temp) < (*(i-first)) )<br />
{<br />
(*i) = (*(i-first));<br />
}<br />
else<br />
{<br />
break;<br />
}<br />
}<br />
(*i)=(*temp);<br />
}<br />
}
I'm trying to make it so I can pass in any iterator from any container, however this won't even compile.
Mike - I love to program!
|
|
|
|
|
allenmpcx wrote:
however this won't even compile
and the compiler says...???
(please be complient and provide all the infos that could help man)
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I was actually able to fix the previous problem by implementing std::iterator_traits< typname Iter >, however, is there a way to make a quicksort algorithm using iterators? I saw lots and lots of implementations using integers, but I need my quicksort algorithm to accept an iterator from the list or a vector. Is this possible?
Mike - I love to program!
|
|
|
|
|
Hi, i'm a newbie programmer fascinated by the inner workings of search engines. I would like to know if any one has an idea what language(s) would a search engine like google use, and what language would you use if you were planning to create a very very basic web search engine. And also, and since i'm a C++ programmer, I wanted to know if C++ could play any role in this job!
|
|
|
|
|
Silly answer: Google specifically uses pigeons! .
Real answer - I suspect google and the like use C and C++ as their mainstay for the actual search technology. No evidence to back this up, mind. I do know that Google use Python as their script language; indeed their support forum pages seem to run exclusively in Python.
As for implementing itself - it's a daunting task. First you need a way of getting the data. You'll need a way of querying many web sites and storing the pages in an indexable way - as Patricia_tries, or one of many many other clever ways of storing data for searching. You'll need a huge amount of storage for this kind of thing - I dread to think how big Google's databases are. You'll also need a lot of internet bandwidth to suck in all the pages you want to index. Of course, if you're only interested in learing about how these things work, you can scale back and just index say one site. For that, you could build a little SQL database of all the words on the site linking to the page the words are found on, etc. This 'spider' program is an ideal candidate for a C/C++ application.
Then you need a way of searching through the data; a web application is usually the way to present web searches. Either write a cgi-bin script for your web server (e.g. Apache) or implement it as a plugin directly to the web server. Or, if you're just more interested in getting something up and running quickly, perhaps consider Python, PHP or Perl extensions to your web server, querying the SQL database you made in part 1.
Hope that helps - happy coding!
Matt Godbolt
Engineer, ProFactor Software
StyleManager project
|
|
|
|
|
Hello! I have just started to learn about linked list and would like to try to insert a set of random numbers into a linked list. I'm confused as to how to go about. I can insert a single number but dont have a clue as to how to do it with set of number. thanks for the help.
|
|
|
|
|
eprt wrote:
I can insert a single number but dont have a clue as to how to do it with set of number.
How is the set stored ? The most obvious way to add random numbers is in a loop - they are not pre existing data, they are random, so just keep your random number generator passing values to push_back until you have as many as you need.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I was wondering if someone could be so kind as to explain or recommend an article/ book that could help explain this for me.
I have a question about Handles. What happens to the underlying object when there are no more handles pointing to it?
Is it lost in memory somewhere or does it get deleted and cleaned up for you?
here is an example.
<br />
ref class A {<br />
public:<br />
property Int32 i;<br />
};<br />
<br />
int main(array<System::String ^> ^args) {<br />
A^ foo = gcnew A();<br />
foo->i = 5;<br />
A^ bar = gcnew A();<br />
bar->i = 13;<br />
<br />
foo = bar;<br />
<br />
return 0;<br />
}
What happens to the first object that has a value of 5?
Since, I no longer have a handle to it, will it still be floating around in memory somewhere?
Thank you,
|
|
|
|
|
If you call gcnew, you're asking for a managed object which means it will be garbage collected for you.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi
i have to implement a neural network but unfortunately i have no experince or idea how to implement or start implementing a artificial neural network. if anyone could please guide me how to start implementing or show an example of implementing any simple artificial neural network or any evolutionary algorithm it will be a great help.
|
|
|
|
|
Hmm... maybe you can start by checking out pseudonym67's article here: Neural Net Part 1 and then continue with pt 2 and 3. Also I remember reading an article about OCR using neural nets that was also implemented using .NET. You may want to do a search... maybe narrow your search a little after you learn a bit about what you're actually searching for.
good luck!
|
|
|
|
|
Hi, I'm new to managed C++ and I was wondering how could I use fopen from managed C++
I have to call a legacy function that uses FILE but when i try to compile my code I get the following errors
fatal error LNK1120: 2 unresolved externals
error LNK2020: unresolved token (0A00002C) delete
error LNK2020: unresolved token (0A000018) _CxxThrowException
the code looks something like this
#pragma once
using namespace System;
//using namespace System::IO;
using namespace System::Runtime::InteropServices;
#include <openssl rsa.h="">
#include <iostream>
namespace OpenSSLWrapper
{
public __gc class RSAWrapper
{
public:
int RSAEncryption()
{
RSA *privateKey;
FILE *keyFile = fopen("C:\\Documents and Settings\\isaac\\Desktop\\Factura\\.key", "r");
if (keyFile == NULL)
return -1;
fclose(keyFile);
Byte sourceArray[] = __gc new Byte[2];
Byte encryptedArray[] = __gc new Byte[5000];
{
unsigned char __pin *source = &sourceArray[0];
unsigned char __pin *encrypted = &encryptedArray[0];
sourceArray[0] = 7;
sourceArray[1] = 5;
}
return 0;
}
};
}
Thanks in advance
Isaac B
|
|
|
|
|
How you have created this project?
I've tested your code, with project created in VC++ project--> console Application(.Net) and didn't get any error.
|
|
|
|
|
I've got a little problem with some code :
My program is in C, doesnt'use use any custom or foreign libraries !
No compile errors are noticied and it works as i want when VS start the app in release and debug mode. But when i try to execute outside (without VS), simply doubleclicking on the exe; my program hang ! They hang not at the same point during the execution.
My program use a lot of pointers, and malloc, which are freed without memory leaks !
Please help !
Thanks for incoming answers !
|
|
|
|
|
Hi,
Do you have any large arrays statically allocated?
I take it that if you have no errors, there are no warning either?
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
You do not use any foriegn libraries, but the C run time library used is different in debug/release builds and heap management is quite different in debug/release builds. Debug takes care of when you overwrite array bound etc..
but release doesnt..there are differences like this.
|
|
|
|
|
hai guys
difference dynamic & static in window programming.
b.raju
|
|
|
|
|
static will have all the MFC in your exe no need for MFC dll`s a very large file
dynamic will have mfc in separate dll`s ...
NG
|
|
|
|
|
convert interbase database file into sql server database
My question is that through interbase database i have text file and again i want to convert that file in sql server database or any ms-access database is it possible so what r the steps.....
plz reply soon..
brijesh
convert interbase database file into sql server database
My question is that through interbase database i have text file and again i want to convert that file in sql server database or any ms-access database is it possible so what r the steps.....
plz reply soon..
brijesh
|
|
|
|
|
I've been working on a .NET component for some time and I recently ran into an issue I could'n find any documentation for so far. Basically the .NET assembly should compile into a mix-mode DLL. That is, the assembly contains a managed class that wraps up a __nogc class that performs some time-sensitive operations on the serial port. The __nogc class spawns a thread that monitors the serial port and that writes to a buffer. In order to make sure that the rest of the program, that sits in a different thread, doesn't conflict with the monitor thread when competing for access to the buffer, I'm using the InterlockedExchange64 and InterlockedExchangeAdd64 functions in the unmanaged class. That seems to prevent the assembly from further beeing accessible to c# .NET applications. When open in the Object Explorer, the assembly shows up fine but when included in the project and instantiated a System.IO.FileLoadException is thrown by the system. It almost looks like there is a permission issue with the asssembly. But that is not the case, I've made sure that all the security policies are reset to default and tried loading the assembly in the "Evaluate Assembly" tool. That didn't work. The "Evaluate Assembly" tool shows an error message saying that the assembly could not be loaded.
So, I'd like to know what is the reason that I can't use Interlocked methods in the unmanaged class or if there is a way around that. Keep in mind that i'm trying to optimize for speed.
Feel free to ask for more details.
|
|
|
|
|
Well... it seems that not a lot of people took interest in this post, nonetheless have I got an answer. Anyway, I found the answer on another forum and thought to complete this post with the explanation and some thoughts.
Basically, the problem was using the InterlockedExchange64 instead of the regular InterlockedExchange. Some say that the InterlockedExchange64 is designed for 64bit OSes and that's the reason it was making my assembly not load. That sounds interesting, but what's even more interesting is that the DLL was compiling without problems with the 64bit version of the function. It's a mistery. Also it's interesting that the IntelliSense is picking up InterlockedExchange64 but not the regular one... definetly something odd.
Enough said, I can now load the assembly in the Evaluate Tool and it looks good so I'm on to further testing it.
|
|
|
|