|
Thank you very much, Cool Ju, the coding is working now!
|
|
|
|
|
( maybe not the best wording for my question )
Let's say I have a vector :
std::vector< BaseObject* > myVector;
I can have an iterator like :
std::vector< BaseObject >::iterator it;
That will move on the vector.
now, if I have a class hierarchy with the BaseObject class as the class parent :
class Derive1 : public BaseObject {};
class Derive2 : public BaseObject {};
myVector.push_back( new Derive1 );
myVector.push_back( new Derive2 );
Is there a way with STL to iterate only on some type of object in the vector ?
For example, only iterator on the object of the type Derive1 instead of iterating over the whole list and manually each time check to see if it's of the right class ?
Or do I have to do a bigger wrapper over the vector ?
Thanks.
Max.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
|
The only way I can think of is using std::remove_if with a predicate function that does a dynamic cast. Not very pretty, IMO.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
IMHO the design is broken.
Relying on RTTI to query a heterogeneous collection either through a hand-rolled function or within the function object of the BOOST selective iterator mentioned is poor design.
This is C thinking within C++
I would suggest a rethink that does not sacrifice type safety.
Why do Derive1 & Derive2 have to be in the same collection?
They are not the same why try and treat them as if they are and then try and recast them?
|
|
|
|
|
#include <iostream>
#include <iomanip>
using namespace std;
bool Solve(int mat[][8], int x, int y);
void print(int mat[][8]);
void Initmat(int mat[][8]);
bool isvalid(int x, int y);
int counter=1;
int main() {
int mat[8][8];
Initmat(mat);
cout << "Generating solution...";
if (Solve(mat, 0, 0))
print(mat);
else cout << "No solution found" << endl;
return 0;
}
void Initmat(int mat[8][8]) {
for (int x = 0; x < 8; x++)
for (int y = 0; y < 8; y++)
mat[x][y] = 0;
}
void print(int mat[8][8]) {
cout << "Solution found!" << endl;
for (int x = 0;x < 8; x++) {
for (int y = 0; y < 8; y++)
cout << setw(4) << mat[x][y];
cout << endl;
}
}
bool Solve(int mat[8][8], int x, int y)
{
bool done=false;
if (counter == 65)
return true;
if (isvalid(x,y) && (mat[x][y] == 0))
{
mat[x][y] = counter; counter++;
if (!done)done=Solve(mat, x+2, y+1);
if (!done)done=Solve(mat, x+1, y+2);
if (!done)done=Solve(mat, x-1, y+2);
if (!done)done=Solve(mat, x-2, y+1);
if (!done)done=Solve(mat, x-2, y-1);
if (!done)done=Solve(mat, x-1, y-2);
if (!done)done=Solve(mat, x+1, y-2);
if (!done)done=Solve(mat, x+2, y-1);
if (!done){mat[x][y] = 0;counter--;}
}
return done;
}
bool isvalid(int x, int y) {
return ((x >= 0) && (x < 8) && (y >= 0) && (y < 8));
}
www.topsites.co.il
|
|
|
|
|
|
Howdy folks,
I'm having a little problem with FindFirstPrinterChangeNotification that has got me baffled. When I call this function on a laptop running XP Pro SP2 I get this error: This function is not supported on this system.
However this same .exe works fine on the other XP systems I've tested it on and calls the function with no problems.
If anyone has any insight into what could be causing this problem I would be very grateful for the help.
Thanks folks.
|
|
|
|
|
Flit wrote: When I call this function on a laptop running XP Pro SP2 I get this error: This function is not supported on this system.
So GetLastError() is returning ERROR_CALL_NOT_IMPLEMENTED ?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Hi DavidCrow, thanks for the response.
FindFirstPrinterChangeNotification returns INVALID_HANDLE_VALUE .
GetLastError returns ERROR_CALL_NOT_IMPLEMENTED .
|
|
|
|
|
Are you using a different printer on the laptop? Is it possible that ultimately it's the printer driver that is saying "I don't support the notification that you've asked for"
|
|
|
|
|
Hi Graham, thanks for your help you set me on the right track.
I installed a new printer on the laptop and it worked fine, the printer I was testing with previously was a network printer.
I went to check on the network printer and it turned out that one of the helpful folk here had unplugged it because they needed the power outlet. I guess this happened between my succesful tests and when I started testing on the laptop.
I've added in some code to disregard any printers that aren't available and it's working fine.
Thankyou.
|
|
|
|
|
I'm writing an add-in for IE and i try to make a call to IWebBrowser::Navigate2 .
I provide an url string with a Google query, containing an already encoded japanese word to be searched. Unfortunately, the browser transforms the '%' characters into '%25', a sadness
Repeating the same procedure, with an IE control embedded into a dialog-based application, works just fine. So, i suppose it should be just a matter of browser control settings.
Do you know how could i get rid of this issue?
"dire io è lento, dire noi è rock"
rechi+
|
|
|
|
|
Bogdan Rechi wrote: I provide an url string with a Google query, containing an already encoded japanese word to be searched. Unfortunately, the browser transforms the '%' characters into '%25', a sadness
What about InternetCrackUrl and InternetCanonicalizeUrl api buddy
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
ThatsAlok wrote: InternetCrackUrl and InternetCanonicalizeUrl
Hi Alok, thanx for the reply.
I don't know about the InternetCrackUrl function. InternetCanonicalizeUrl is not working good for the UTF-8 stuff i needed. Anyway, i already encoded the URL by myself and i'm trying now to pass it to the browser. Normally, it should take it and execute it without any conversion but, unfortunately, it takes care about the '%' characters and everything explodes
I don't know how this is to be done but it has to be a way to do it. Google Toolbar itself is a succesful example.
"dire io è lento, dire noi è rock"
rechi+
|
|
|
|
|
Hi, I 'm trying to import a template class from dll A to another one, dll B, where I'm subclassing it and instantiating it. However I get the following linking error:
xmlCoreBuilder error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall MAGE::Builder<class mage::scene="">::Builder<class mage::scene="">(void)" (__imp_??0?$Builder@VScene@MAGE@@@MAGE@@QAE@XZ) referenced in function "public: __thiscall xmlCoreBuilder::SceneBuilder::SceneBuilder(void)" (??0SceneBuilder@xmlCoreBuilder@@QAE@XZ)
In the following error Builder is the base template class defined in dll A and SceneBuilder is a specialized sub-class of the former defined in dll B. I get the linking error when creating an instance of the sub-class in dll B:
xmlCoreBuilder::SceneBuilder* b = new xmlCoreBuilder::SceneBuilder;
I'm suspecting that I might have that problem because I export a template class, but I'm not sure. Can you think of anything?
Thank you,
Themis
|
|
|
|
|
Hello,
You can't export template classes. This is because code is generated at compile time and DLL's work at runtime. The only way to 'export' templates is to provide the source code. This needs to be in the header file anyway..
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
DLL A:
BldT.h:
template<class TT> class BldT {...};
typedef BldT<long> BldLong;
#include "BldT.i"
BldT.i:
template<class TT>
BldT<TT>::BldT( void ) {...}
...
BldT.cpp:
// The following will export all methods from BldT<long> template instance
template class __declspec(dllexport) BldT<long>;
DLL B:
SBld.h
class ScnBld : public BldLong {...};
You will still need to access BldT.h from DLL B to compile.
However, you shouldn't need to provide BldT.i and can remove the #include "BldT.i" from the BldT.h that DLL B uses.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
what is wrong in this code? thank you
#include "stdafx.h"
#include "windows.h"
typedef HANDLE(*pAdd)(LPCSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE);
pAdd pfAdd;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
HANDLE g_hCapFile;
HINSTANCE hDLL;
hDLL = LoadLibrary("c:\\winnt\\system32\\kernel32.dll");
pfAdd = (pAdd)GetProcAddress(hDLL,"CreateFileA");
g_hCapFile=(*pfAdd)("c:\\ftp\\pippo",GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
return 0;
}
bocbe
-- modified at 10:50 Friday 11th November, 2005
|
|
|
|
|
The windows.h should have been included in the stdafx.h
There is no check that handle to DLL is null prior to trying to get procedure address.
There is no check that pfAdd is not NULL prior to using it as a pointer to a function.
The freaking path to kernel32.dll is hard coded!
I have several Windows XP installations, and the OS is on drive H:
There may be others, but this is enough to make me wonder if the softwae programmer knows what he is doing
|
|
|
|
|
|
In addition to the lack of error checking, what is the value of g_hCapFile after the call to CreateFileA() ? If it is INVALID_HANDLE_VALUE , then what does GetLastError() return?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
In this code only at the last line the system (if you try in debug mode) will give you the error: "calling convention is wron
bocbe
|
|
|
|
|
Hi All,
I have a makefile project and I want to call COM (ActiveX control) in the project.
The code to call COM in makefile is as follows:
Files included for COM support are:
#include <objbase.h>
#include <comdef.h>
#include <rpc.h>
#include <rpcndr.h>
#include <basetyps.h>
//I am just putting the COM calling code let me know if I m doing the right way.
HRESULT hr = CoInitialize(NULL);
if(FAILED(hr))
{
printf("CoInitialize Failed\n");
return 0;
}
IMyInterface* pInt = NULL;
hr = CoCreateInstance(CLSID_MyInterface, NULL, CLSCTX_INPROC_SERVER, IID_IMyInterface, reinterpret_cast<void**> (&pInt));
if(SUCCEEDED(hr))
pInt->Connect(); //This is the COM funtion that I want to use
pInt->Release();
CoUninitialize();
It compiles fine but when I try to build it gives me Linking Error...
MyClass.OBJ : error LNK2001: unresolved external symbol __imp__CoUninitialize@0
MyClass.OBJ : error LNK2001: unresolved external symbol __imp__CoCreateInstance@20
MyClass.OBJ : error LNK2001: unresolved external symbol __imp__CoInitialize@4
MyApplication.EXE : fatal error LNK1120: 3 unresolved externals
NMAKE : fatal error U1077: 'link' : return code '0x460'
Please help me on this. Thanks in advance.
Ashok
|
|
|
|
|
Sounds like you need to add ole32.lib to the project's lib files.
|
|
|
|