I would recommend reading the following thread for detailed explanation on why cin is better to be used in while loop.

[url]http://www.parashift.com/c++-faq-lite/input-output.html[/url]
[15.2] Why does my program go into an infinite loop when someone enters an invalid input character?

another thing if you want to break on the size of array.. why don't you use. the for loop?

[code]
for (int i=0; i<10; ++i)
{
cin >> c;
a[i] = c;
}

[/code]

Hi,
your question is bit unclear... what are you storing in the multimap logically. What I've understood is that you want to get the multiple values against the same key

[code=cpp]
multimap<int, string> mm;
mm.insert(std::make_pair(1, "a"));
mm.insert(std::make_pair(1, "c"));
mm.insert(std::make_pair(2, "d"));
mm.insert(std::make_pair(2, "e"));

typedef pair<multimap<int, string>::iterator, multimap<int, string>::iterator>  Pair_Range;
Pair_Range  pRange = mm.equal_range(1);

for (multimap<int, string>::iterator it = pRange.first; it != pRange.second; ++it) {
    cout << it->second<<endl;
}

[/code]

Hope this helps

iamthwee commented: no -4

search Longest Common Subsequence algorithm. and modify that algorithm to meet your need.

when I was learning this topic. I followed the very good series of articles on code project, check the below link
[quote]
[url]http://www.codeproject.com/KB/atl/atl_underthehood_.aspx[/url]
[/quote]

Hope above helps.

Thank you mcco for providing me the definition of RECT structure

kindly provide me the values (numbers), It seems that your expression evaluates to zero thats why I've asked to provide me the values not the RECT members. :).

What are the values of RECT members?

hmmmmmmmmmm, I've come up with some solution to you problem hope this might help you.
[code=cpp]

class ICommand {
public:
virtual ~ICommand() = 0 { }
virtual void ExecuteCallBack(int iCommandId) = 0;
};

// Command Base Object.
template<class T>
class Command : public ICommand {
typedef void (T::*Delegate)(int a);
vector<Delegate> memFunctions;
public:
Command() { }
void RegisterCallBack(Delegate func) {
memFunctions.push_back(func);
}

Delegate GetCallBack(int idx) { 
    // add checking of constraint.
    return memFunctions[idx];
}

// you can add functions like 
// void executeAllCallBacks() = 0;
virtual void ExecuteCallBack(int iCommandId) = 0;

};

class Administrator : public Command<Administrator> {
protected:

virtual void ExecuteCallBack(int iCommandId) {
    (this->*GetCallBack(iCommandId))(8);
}

Administrator() { }

public:

void Add(int a) {
    cout << "Administrator Add"<<endl;
}

void Remove(int a ) {
    cout << "Administrator Remove"<<endl;
}

static Command<Administrator>* GetInstance() {
    return new Administrator;
}

};

class HR : public Command<HR> {
protected:
virtual void ExecuteCallBack(int iCommandId) {
(this->*GetCallBack(iCommandId))(8);
}
HR() { }
public:

void Add(int a) {
    cout << "HR Add"<<endl;
}

void Remove(int a ) {
    cout << "HR Remove"<<endl;
}

static Command<HR>* GetInstance() {
    return new HR;
}

};

int main ()
{
Command<Administrator>* obj = Administrator::GetInstance();
obj->RegisterCallBack(&Administrator::Add);
obj->ExecuteCallBack(0);

Command<HR>* obj2 = HR::GetInstance();
obj2->RegisterCallBack(&HR::Add);
obj2->ExecuteCallBack(0);

// now the interesting Part.
vector<ICommand*> vec;
vec.push_back(obj);
vec.push_back(obj2);

for(size_t i=0; i<vec.size(); ++i) {
    vec[i]->ExecuteCallBack(0);
}

return 0;

}
[/code]

Hope this help, you can further comment on this as well.

bool, true, false are already keyword in C++. you don't need to define enum for it.

Hi FirstPerson,

I've tweaked your code to meet your needs, I think you are trying to acheive something like this.
[code]

class Tetris {
public:
bool DrawLine(unsigned int iColId) {
cout << "Draw Line of Tetris"<<endl;
return true;
}
};

template<typename Type>
class vec2D
{

typedef bool (Tetris::*MFPtr)(unsigned int ID);
MFPtr mydrawFuncPtr;

private:
unsigned int Col_id;
public:
Type x;
Type y;

vec2D(Type x0,Type y0) : x(x0), y(y0) { }
vec2D() : x(0),y(0){ mydrawFuncPtr = 0; }

void reset() { x  = 0; y = 0; }

//Enables each object member to have its own unique draw func. 
void setDrawFunc(MFPtr drawFunc  ) {  mydrawFuncPtr = drawFunc;}

//get-set methods
unsigned int Color() { return Col_id;}

void Color(int i) { if(i < 0) Col_id = 0; else Col_id = i; }

// WRONG.
//void drawShape(vec2D<Type>& obj,unsigned int colID) 

//CORRECTED:
void drawShape(Tetris& obj,unsigned int colID) 
{       
    (obj.*mydrawFuncPtr)(colID);
}

};

int main ()
{

vec2D<int> vec2DTetris[10];         // use this array.
vec2DTetris[0].setDrawFunc(&Tetris::DrawLine);

Tetris t;
vec2DTetris[0].drawShape(t, 4);

return 0;

}
[/code]

Hope the Above Code help

I've few questions,

[code]
FrameVisitor::FrameVisitor()
{
Frame();
frames = get_frames(myfile);
}
[/code]
you have passed 'myfile' as a parameter in fstream where it is defined?

change the following Code.
[code]
list<Frame> FrameVisitor::get_frames(fstream& myfile)
{

    char * memblock = new char [4]; //1º 4 bytes da frame...header.
    char * start = memblock;
    int i = 0;
    char c;
    list<Frame> lst;

...........
}

// to the below one.
list<Frame> FrameVisitor::get_frames(const char myfilePath)
{
fstream myfile(myfilePath, ios::in);
char
memblock = new char [4]; //1º 4 bytes da frame...header.
char * start = memblock;
int i = 0;
char c;
list<Frame> lst;
...........

}
[/code]

Try to pass the filePath not the streams between functions
just open the stream where required and close it after using.

as far as the problem is concerned there is no copy constructor defined for streams, whenever pass by value they'll cause problems.
check your code of class frame as well. rather than storing the stream as a member keep the file path as a member.

Hope this helps.

I don't think Command Design pattern best matches your need,

what you can do is simply create a Class that holds the map of Objects of type administrator, HR, Staff and value part contains the vector of member funciton pointers. now in each object administrator, HR or Staff create some integral type upon which you'll decide which member function would be executed for selected object. or either call every registered member funciton.

[code]
//something like below.
typedef void (T::*MEMFuncPtr)(int id);
map<T, vector<MEMFuncPtr> > fMap;
[/code]
check for the Chain of Responsiblity Design pattern. your requirement matches that pattern.

As far as Factory Method is concern its simple man. provide the Create function in every member class and create the abstract factor which would be templatized.

it depends on the compiler rather than C++, you should see the compiler reference manual.

I think you are trying to acheive the below one.

[code=cpp]
template<class T>
class Foo {
typedef void (T::*MFPtr)(int id);
MFPtr funcPtr;
public:
void SetDrawFunction(MFPtr memFunctionPtr) {
this->funcPtr = memFunctionPtr;
}

void Draw(T obj, const int Id) {
    return (obj.*funcPtr)(Id);
}

};

class Bar {

public:
void DoIt(int id) {
cout <<"Ahaan I am Called from Foo"<<endl;
cout << "Value of my Id is : "<<id <<endl;
}
};

int main ()
{

Foo<Bar> f;
f.SetDrawFunction(&Bar::DoIt);

Bar b;
f.Draw(b, 4);

return 0;

}
[/code]

basically you are declarnig pointer to function and storing pointer to member function.

sorry PETER_APIIT but your design has several flaws, describe you requirement a bit, then I will tweak your design to meet your needs.

Read the following Link Carefully and check for MACRO & GUID that needs to be defined in case of XP, I am assuming that you are good in understanding msdn doc. If you still find it difficult to implement I will provide you the sample.

[url]http://msdn.microsoft.com/en-us/library/bb773352(VS.85).aspx[/url]

Hope the above link helps.

Hi,
why you've called LoadBitmap(...) in WM_CREATE message? I am sure your problem will be resolved if you change WM_CREATE to WM_INITDIALOG.
further you should learn and understand the difference between WM_CREATE & WM_INITDIALOG.

peek basically reads the next available character without moving the file pointer.

for example if text file contains the following text
[quote]
Hello, World
[/quote]

and if you execute the following psuedo Code
[code=cpp]
int main ()
{
// open stream.
char v = f.peek();

// the below line will print 'H' but will not extract this character from stream.
cout << v <<endl;
}
[/code]
if you don't want to move your reading cursor and wants to check which character will be read next you should use peek.

yes Its seems fine with a cursory look.

Good luck (Y).

try the below one
[code]
//HANDLE hPort = CreateFile("COM1", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
HANDLE hPort = CreateFile(TEXT("COM1"), GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

[/code]

Hope the above help, you didn't ask what is LPCWSTR ok :). So I am providing the solution only :P.

@firstPerson the default Constructor & Destructor are not always trivial at the Compiler level, to users it might be...

Hi lotrsimp12345,

This usually irritates the programmer that why the compiler emits a default constructor.

Let me explain you a bit detail of how C++ standard dictate about default constructor and its semantics.

if your class contains primitive types, then your default constructor would be trivial i.e.
[code=cpp]
class Foo {
public:
int a;
}
[/code]
if we consider the Foo class its default constructor would be trivial i.e. doesn't modify the state and probably member "a" contains the garbage (or some 0xCCCCCCCC etc). Basically in C++ its always the programmer's responsiblity to intialize the values. This is what standard tells us. Logically if we look with the eye of programmer it seems irritating for us to explicitly intialize the value, yes it is, but we have some other facilities (default argument values) in the language to acheive the same.

[code=cpp]
class Foo {
Bar b;
}
[/code]

In above code Bar is the subobject which must be initialized before the intialization of Foo in this case compiler synthesized the constructor which in turns calls the default constructor for Bar. same goes for inheritance as well and obviously destructor would release the memory by calling the destructor of subobjects.

if C++ default constructor initializes the memory to "ZERO values" for primitive types then the name of default constructor should be "ZERO Constructor" :) rather than default constructor.

DangerDev commented: very informative. +3

Serialization & Deserialization technique would help you in acheiving this. or rather use the Boost which will provide you serialization & deserialization by not doing lot of work.

check the below link
[url]http://www.codeproject.com/KB/cpp/InterprocessSingleton.aspx[/url]

I think you are mixing the pointer to Function with Pointer to member Function, I am giving you a little example on How to solve your problem.

[code=cpp]
class Foo {
public:
bool operator()(const int a) {
return (a==1);
}
};

// Don't pass Pointer to Function.
typedef bool (*PF)(const int);
//bool DoSomething(PF pFunction) {
bool DoSomeThing(Foo& f) {
return f(1);
}

typedef bool (Foo::PMF)(const int a);
bool DoSomeThingElse(Foo& obj, PMF pMemFunction) {
return (obj.
pMemFunction)(1);
}

int main()
{
Foo f;
bool ans = DoSomeThing(f);
PMF pMemFunc;

bool memFunction = DoSomeThingElse(f, &Foo::operator ());

return 0;

}
[/code]

In the Code above I commented the pointer to function because in your case you are using Functor or Function object which are treated as pointer to member function, so I beleive passing the object directly or passing the object and pointer to member function are the solutions to your problem. I think code explains the difference between the two.

Hope this helps!.

i) create an event and check that event in the child thread

ii) signal the event from main thread when you want to exit

iii) call UnhookWindowEx() and release resouces in the child thread.

psudo code
[code=cpp]

LONG WINAPI ThreadFunc(LPVOID arg)
{

HANDLE hEvent = OpenEvent(...,"ChildEvent");

// Perform Coding.

// here you can check whether the event is signalled or not.
WaitForSingleObject(hEvent, INFINITE);

}

int main ()
{
// .. Something like below
HANLDE hEvent = CreateEvent(...);
HANDLE hThread = _beginthreadex(...., ThreadFunc);

// perform the coding of main thread.

// Signal the Event, if the child thread is still running.
GetExitCodeThread(hThread, &dwExitCode);
if (dwExitCode == STILL_ACTIVE)
SetEvent(hEvent);

// still for the safe side
WaitForSingleObject(hThread, INFINITE);

CloseHandle(hThread);
CloseHandle(hEvent);

}
[/code]

Well in the ThreadFunc I've called the WaitForSingleObject(..., INFINITE) you must know how to change it to wait for the specified Time, if you are not willing to wait synchronously (INFINITE LY).

Another Way is use the SendMessage Or PostMessage API.

if you are using pthread then you can use the following API.

[code]
int pthread_attr_setschedparam(pthread_attr_t tattr, const struct sched_param param);
[/code]

consult google for such questions :). it will show you more answers.

I am sure that your BSTreeNode calss must be template class and you should provide the template argument to this as well.
like
[code]
BSTreeNode<DataType, KeyType> BSTree<DataType, KeyType>::findMin (BSTreeNode<DataType, KeyType> root) const {
// Implimentation ...
}
[/code].
otherwise provide the implementation of class BSTreeNode to identify the exact error.

Hope this helps

First of all for all native Applications written in C/C++ no Framework is required, well as you are using MFC in your project I think you must know the basics of Dll & CRT. In VS2008 create a Win32 Console Application and write a simple hello world program deploy that program on the machine and you'll be sure that no Framework requirement is there, check the CRT you are linking with make it statically linked, in your case I think you are dynamically linking with CRT /MDd compiler switch MSVCRTD.dll which is the default option in VS2008. try using the /MTd or /MT which will link statically with your binary.

Install the microsoft Redistributable Package for your version (VS2008 in your case) on the machine, on which you are going to deploy the .exe. If you are using MFC then you either statically link with MFC or if you dynamically link with it then you must ship mfc with that.

Learn static and dynamic learning for more informaiton.

In any case you don't need to install the framework on the target machine if you are using the Native languages C/C++.

Hope this helps

[QUOTE=selsium;929931]hi folks,

I have some 247 warnigs are same type warning

C4996: 'fopen' was declared deprecated

I am using makefile to compile my cpp program in Visual studio 2005.

I have added _CRT_SECURE_NO_DEPRECATE in preprocessor definition too. but still I do get the warnings . Could anyone help me?[/QUOTE]

I assume that you understand why Microsoft Compiler gives this warning... so explaining the solution...

if you use precompiled headers add the following lines in the stdafx.h and rebuild the project.
[code]

define _CRT_SECURE_NO_DEPRECATE

define _CRT_NONSTDC_NO_DEPRECATE

[/code]

another would be include the warning in the ignore specific warning in the project settings or defining the following pragma before using any deprecated function.

[code]

pragma warning (disable : 4996)

[/code]

or add the compiler directive /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE.

Well I used the IDE to compile, and I use the _CRT_SECURE_NO_DEPRECATE in the preprocessor and it has worked for me, didn't try with make files, but I am sure with the first solution that it would work if you are using the precompiled headers, disabling the 4996 warning altogether is not a good practice I think, although it is another solution to your question.

Hope the above help. Get back to us if you still get warning.

tom Gun
[Quote]

I have a function under Base class and at the definition tine of this base class function I need to call another function which is define under the Derived class. how to do this??

[/Quote]

As per the OOP paradigm strickly speaking in OOP, whenever you need the default behavior in Generic Type & want to specialize the behavior in derived you use the polymorphic behavior. Or if you just wanted to delegate the implementation on derive classes you can do so the concept of pure virtual function in that scenario generic type cannot define the implementation perfect example is shape heirarchy in that Draw () = 0 must be pure virtual and derived classes triangle, square etc should implement that.

well I look this query as a try to acheive [Quote] Multiple dispatch ideom[Quote].

Well I can write article on that, but try to reuse the existing one over the internet :) hope this helps

Read about OWNER DRAW Window's Style and Windows Subclassing and also Non Client Paint Message.

Following Link would help but pre-requisit are the above two concepts.

[url]http://www.codeguru.com/cpp/controls/controls/tabcontrols/article.php/c2237[/url]

the Below is the link of VB Code just check How API's are being called.
[url]http://www.vbaccelerator.com/home/VB/code/Controls/Tab_Controls/MDI_Tabs/article.asp[/url]

try this tutorial, if no luck then get back here again :). I will debug with you again..