ArkM 1,090 Postaholic

You declare the first arrAscendingOrder and showArrPtr paremeter as an array of pointers to double ( Why?! ). However the only array (accessed via score pointer) in your program is an ordinar array of doubles. You are trying to pass it in these functions.

See your showArray correct parameter declaration as array of doubles.

That's all.

Yet another defect: you don't check user input. It's extremely bad practice. Avoid it.

if (!(cin >> numscores) || numscores <= 0) {
    // not a number or incorrect value...
}

Use code tag with the language specifier for your snippets:
[code=cplusplus] source

[/code]
Mark wrong statements in your snippets. As usually nobody want to copy/paste all texts in IDE to reproduce your syntax errors.

ArkM 1,090 Postaholic

1. Wrong assignment operator (default member by member assignment can't work with such objects - think why).
2. No correct copy constructor (default copy constructor can't copy such objects). That's why your program crashed.
3. Some other defects ;)

StRiNg::StRiNg(const char* s) // const !
{
    if (s == 0) s = ""; // you forgot to test nullptr
    // now make as usually
}
StRiNg::StRiNg(const StRiNg& s) // copy constructor
{
    // make new dynamic copy of s
}
StRiNg& StRiNg::operator=(const StRiNg& s)
{
    if (this != &s) {
       delete [] sTr;
       // now make new dynamic copy of s   
    }
    return *this;
}
// GetString, bye forever:
operator const char*() const { return sTr; }

No needs in operator=(const char*) now: you have const char* to StRiNg constructor.

std::ostream& operator <<(std::ostream& os, const StRiNg& s)
{
    return os << sTr;
}

Now you can print your StRiNgS aS uSuAlLy.

ArkM 1,090 Postaholic

Keep it simpler ;)

bool getSSN(string& ssn)
{
    while (cout << "Enter SSN as ddd-dd-dddd: ", cin >> ssn) {
        if (ssn.size() == 11 && ssn[3] == '-' && ssn[6] == '-') {
            int digits = 0;
            for (int i = 0; i < 11; ++i)
                if (isdigit(ssn[i])) digits++;
            if (digits == 9)
                return true;
        }
        cout << "Wrong SSN. Please try again...\n";
        cin.ignore(1000,'\n');
    }    
    return false;
}
ArkM 1,090 Postaholic

1. You don't remove items from an array, you print all elements except removeItem. It's a solution of another problem.
2. Count removeItem occurences then print a proper message(s) if counter == 0 or counter == ARRAY_SIZE. Let removeAll returns this counter value or a new number of array elements (ARRAY_SIZE - counter).

ArkM 1,090 Postaholic

NEVER use float data type in math and financial calculations, it has too low precision. Standard C and C++ floating point type is double (have a look at <cmath> header contents).

Use modf library function to separate integer and fractional parts.

songweaver commented: very helpful +1
ArkM 1,090 Postaholic

Take into account that it's impossible to round decimal fractions accurately with binary floating point data ;)
Try to avoid pow function using: it's the most ineffective and inaccurate method in that case.

ArkM 1,090 Postaholic

Look at csurfer's post again!
It was the true solution of your problems (in other words, it was a correction of your mistake ;))...

ArkM 1,090 Postaholic

Think about another approach:

struct IntRange { int minval, maxval; };

struct IntRange MinMax(const int* arr, int n)
{
    struct IntRange range = { 0, 0 };
    if (arr && 0 < n) {
        int i;
        range.minval = range.maxval = arr[0];
        for (i = 1; i < n; ++i) {
            if (arr[i] < range.minval)
                range.minval = arr[i];
            else if (range.maxval < arr[i])
                range.maxval = arr[i];
        }
    }
    return range;
};

int main()
{
    int* numberlist;
    struct Range range;
    ...
    range = MinMax(numberlist,n);
    printf("Min %d\nMax %d\n",range.minval.range.maxval);
	return 0;
}
ArkM 1,090 Postaholic

Did you mean constructor with 'ctor' ?

Of course, ctor is a common abbreviation for constructor (and dtor for destructor) in C++ context. But this syntactical construct named exactly as ctor-initializer in the C++ Standard.
See also http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/

tux4life commented: Thank you for your help ! +1
ArkM 1,090 Postaholic

It's wonderful but just before talking about this code run-time speed and other characteristics correct obvious errors in it. Now you can't compile this code: arr1 is not declared in the merge function (if it's a global variable better don't display this "improved" sort function)...

When you compile this improved merge sort code you can test and profile it - and you will get all answers to your questions...

PS. As usually, xor based solution is much more expensive than a simple swap...

ArkM 1,090 Postaholic

It's class Array2D constructor with ctor-initializer. I hope you can see that it's initial member values definition.

ArkM 1,090 Postaholic

I'm not sure that this info is enough to reproduce and analyze your program error(s). It looks like a very unstable, error-prone code (what happens if code4 string is too short? Right, you catch an exception or get undefined program behaviour).
Some tips:
1. Didn't you know string subscript operator?

if (code4[1] == '/') ...
...
b = code4[2] - '0';
... and so on - you get short and clear code ...

2. Where is else?

if (code4[1] == '/') {
   ...
} else if (code4[3] == '/') { // <= else !!!
   ...
} else {
   ...
}
ArkM 1,090 Postaholic

A name in C is a statically (before execution) defined program artifact, syntacticaly it's an identifier.

There are dynamically (in run-time) created and destroyed data objects and statically (before execution) defined data objects (literal constants). The program can't modify constants (literals).

A variable is a named data object. In other words, it's a data object with (statically defined, see #1 above) name.

Therefore you can't create new variables in run-time because you can't create new names in run-time. All names are defined in your program before execution (in actual fact before compilation).

However you can create new (anonymous) data objects (via malloc library function) and work with them via pointer variables.

ArkM 1,090 Postaholic

Search Google (or what else) for C++ class matrix.
That's a simple improvisation on the topic (in the public domain;)):

/// @file matrix.h:
struct MatrixError {
    const char* what() const { return "Matrix failure"; }
};
/// Incomplete and ineffective but simple
/// number matrix implementation (it works;)
template <typename T>
class Matrix
{
public:
    Matrix(size_t m, size_t n, const T& ival = 0) {
        std::vector<T> irow(n,ival);
        vRows.resize(m,irow);
    }
    virtual ~Matrix() {}

    size_t rows() const { return vRows.size(); }
    size_t cols() const {
        return rows()?vRows[0].size():0;
    }
    std::vector<T>& operator[](size_t i) { return vRows[i]; }
    const std::vector<T>& operator[](size_t i) const {
        return vRows[i];
    }
    Matrix& operator =(const T& val);
    Matrix& operator +=(const Matrix& m);
    bool operator ==(const Matrix& m) const;
    bool operator !=(const Matrix& m) const {
        return !(*this == m);
    }
protected:
    void checkDims(const Matrix& m) const {
        if (rows() != m.rows() || cols() != m.cols())
            throw MatrixError();
    }
    std::vector<std::vector<T> > vRows; 
};
template<typename T>
Matrix<T>& Matrix<T>::operator=(const T& val)
{
    for (size_t i = 0, m = cols(); i < rows(); ++i)
        vRows[i].assign(m,val);
    return *this;
}
template<typename T>
Matrix<T>& Matrix<T>::operator +=(const Matrix& m) 
{
    checkDims(m);
    for (size_t i = 0; i < rows(); ++i)
    for (size_t j = 0; j < cols(); ++j)
        vRows[i][j] += m[i][j];
    return *this; 
}
template<typename T>
bool Matrix<T>::operator ==(const Matrix& m) const
{
    try { // MatrixError handling example
        checkDims(m);
        for (size_t i = 0; i < rows(); ++i)
        for (size_t j = 0; j < cols(); ++j)
            if (vRows[i][j] != m[i][j])
                return false; …
ArkM 1,090 Postaholic

>Apparantly the size_t is typedefed to a unsigned long int on my system. Is this safe to assume its the same on all c++ compilers?

Nope: "The value of the result (of the operator sizeof) is implementation-defined, and its type (an unsigned integer type) is size_t, defined in <stddef.h> (and other headers)."

>Why does 'printf("size of size_t: %d\n",sizeof(size_t ));' make a warning?

Use well-known %lu format specifier for unsigned long int...

>Why cant I do a 63 bit left shift?
1<<63 - constant 1 type is int, not unsigned long int...

>If I had one hell of a machine would this mean that I should be able to allocate an array with this extreme big dimension?

Nope. The language standard does not define max array extent, it's an implementation-defined value.

ArkM 1,090 Postaholic

1. You forgot to add std:: prefix for vector in template parameter.
2. Barbaric construct: hfh<=(int)combi . Make cast before loop.
This code works with VC++ 2008. Yes, it's a bad code: for example, you can initialize 2D vector in a simple, clear and effective manner:

truth_table.resize(n,0);
truth_table_col.resize(m,truth_table);
truth_table.clear();
ArkM 1,090 Postaholic

Bad practice wanted? That's bad practice:
1. C-style 2D array allocation/deallocation functions instead of complete 2D array class with full set of operations.
2. Explicit row parameter in destroy2DMatrix: an erron-prone and inconvenient method.
3. Template function definitions after calls: most of C++ compilers can't process this code.
4. 2D matrix... A matrix is a 2D (2D only) array with specific operators - by matrix definition...
;)

ArkM 1,090 Postaholic

A type (a class) is a set of values + a set of operations. Strictly speaking, a (linked) list is not a simple collection of nodes. It's a collection of values (data) with operators:
- first (or head, or front)
- last (or tail, or back)
- count (or size)
- append (or add, or push_back)
- insert (optional)
- erase
- clear
- next
- prev (optional)
- find
- swap (optional)
- sort (optional)
and so on...

Look at http://en.wikipedia.org/wiki/Linked_lists.
Read about STL list container as an example of true class list.

As usually, a list implementation is a chained (by pointers) collection of nodes. A list node is a term for a value plus internal (as usually, invisible for list users) reference field(s) data structure.

Of course, you may define specialized class list of public nodes with exposed auxiliary next/prev fields. Remember: class list user don't want to take much trouble over these pointer fields. Moreover, it a very dangerous approach (how about unpredictable change of reference fields by wrong user code? ). It's class list member functions job.

ArkM 1,090 Postaholic

Declare const Node* temp in const member functions - that's all. These functions must not modify Node fields but you can modify them via Node* temp pointer.

Yet another remark:
Did you want to implement Linked List class? If so why did you implement Node only class? A list is not a simple Node. Now you are trying to manipulate with list via Node pointers only in C (not C++ ) style. It's an example of a bad class design...

ArkM 1,090 Postaholic

It seems it's your homework... See this forum rules... ;)
Some tips:
1. the scanner (lexical analyser) works "before" preprocessor so your 1st statement is wrong...
2. The C preprocessor is a one-pass text processor...

ArkM 1,090 Postaholic

So you're recommending that I derive classes for each of the constructors I currently have?

???!
You derive a class, not a constructor. Base class constructor executes when a derived class object is created by any its constructor.
Yet another method: define (as usually, private) member function - common initializator. Call it in all your constructors. This method does not work if you must initialize class members via constructors. Alas, in that case you must repeat member initialization list in all constructors.
I think too many constructors is a sympthom of a bad class design. Consider yet another approach: define 1-2-3 constructors then assign a specialization to class objects via special member functions like set, bind, attach etc...

ArkM 1,090 Postaholic

In other words, you are trying to bind 2D array argument (line 9) with 1D array parameter declared in the line 13, then use 1D array parameter as 2D array in the function body (other lines).
Is it surprising that your compiler is surprised at these poetic licenses?

ArkM 1,090 Postaholic
class WonderPoint
{
public:
    bool isValid() const { return valid; }
protected:
    WonderPoint():valid(false) {}
    bool valid;
};
class OrientedPoint:// Oriented POINT- that's cool!
      public StrangePoint // Fields Medal!!!
{
public:
    OrientedPoint()...
    ...
};
ArkM 1,090 Postaholic

Yet another tip: never use exit() in destructors. The program has undefined befavior if exit() is called during the destruction of an object with static storage duration.

However return n; in the main performs local objects destruction then calls this terrible exit function ;)...

ArkM 1,090 Postaholic

Don't stop C++ programs with exit() function (except on severy run-time errors).
Use return exit_code_value; in the main.

siddhant3s commented: He said just what I wanted to say. Right Advice +2
ArkM 1,090 Postaholic

how do i get to project properties?

There is a wonderful thing in VS IDE: the Main Menu (look at the top of the VS window). Select Project | projectname Properties or simply press Alt+F7 (if you can cope with a keyboard ;))...

ArkM 1,090 Postaholic

A classical case. Only base class destructor called because your BaseFoo is not a polymorphic class. It can't deallocate any vectors in the derived class: it knows nothing about its descendants.
Make it as a polymorphic class (fortunately, it's so simple) and see what happens:

class BaseFoo {
public:	
  BaseFoo() {}
  virtual ~BaseFoo() {}
};
ArkM 1,090 Postaholic

Evidently it's impossible to answer the question in common case. It depends on this port nature and features. If no underlied system provided events to wait and react on the port activity the only approach is a "busy wait" (probably it's your case).
Possible approaches:
- Set the lowest (at least lower) priority to your process - let it plays an idle loop role.
- Add passive wait periods (sleeping) - the proper time delay depends on the system shedule characteristics and permissible data stream processing degradation.

ArkM 1,090 Postaholic

Some additions:
stdafx.h is Visual C++ specific pre-compiled headers artifact.
In precompiled headers mode VC++ ignores all lines before #include "stdafx.h". You may switch on/off this mode in Project Properties | Configuration | C/C++ | Precompiled Headers tab.

ArkM 1,090 Postaholic

1. Don't worry, you can "delete" null pointer safety: it's a legal noop.
2. It seems you have a mesh, not a tree. Try to distinct node owners (they allocate another nodes) and node referers (they refers to another nodes but did not allocate them). The node destructor deletes the 1st ones but clears (both sides of) links for 2nd kind of nodes.
3. It seems you have all these troubles because didn't design this data structure and its operations carefully. Now you are trying to solve some partial technical problems (with node destructor, for example). Better try to redesign the project (alas). It's impossible to get working solution on this vague basis...

ArkM 1,090 Postaholic

>Well, considering this is the C++ forum, I didn't think the language specifiers were needed, but fine.
Thank you. Pay attention that the forum engine adds line numbers (for references) and makes some code formatting (easy to read) only for proper code tags with the language specifiers...

>Well obviously it's wrong code. I was asking for help with the right code.
That's exactly why the class definition needed ;)

Add node class (struct) constructor and destructor:

struct node                      
{
    node():parent(0),num(0),level(0) {}
    ~node() {
        for (size_t i = 0; i < children.size(); ++i)
            delete children[i];
            // That's all you need to deallocate branches.
            // However (about another destructor actions):
            // I can't understand what's the parent member role.
            // See insert member: why it's not a parent_in_tree?
            // What's inHelp role?
            // In other words: think about parent ptr target
            // when this node dies...
        }
    ...
};

Now you can use a simple and natural delete nodepointer expression.
Remark: better use capitalized names for your classes (Node, for example).

Now MTree destructor and clear (all the tree) member functions (add them):

~MTree() { delete root; }
void clear() { delete root; root = 0; }

Alas, the class MTree design does not provide an user with a correct and convenient erase (the node with all its branches) member function. The MTree::del public member is wrong: you assign NULL value to the function parameter (called by value) so the original pointer to this …

ArkM 1,090 Postaholic

1. Use code tag with the language specifier!!!
[code=c++] source

[/code]
2. Where is your class definition? Where is your problem destructor definition?
3. >but my compiler didn't like it
Yes, I don't like it too. Probably it's a wrong code.
Where are compiler diagnostic messages? See also #2...
4. It seems you didn't understand my post in the recent thread on this topic. As usually, the only job for the node destructor is to delete pointers in the branches vector. It starts a recursive destruction of all this branch. The branch vector member has its own destructor. It seems you are still mixing a class destructor role and an object memory deallocation via the delete operator.
5. If you call del(this) in a node destructor then you get recursive destructor entry on delete ptr .
6. You are trying to delete all nodes twice in the 2nd snippet...
...and so on...
Please, present your class definition if you want more helps.

ArkM 1,090 Postaholic
std::string& Reverse(std::string& s)
{
    std::string::iterator 
        f = s.begin(),
        r = s.end();
    while (f < r)
        std::swap(*f++,*--r);
    return s;
}
std::string Reversed(const std::string& s) {
    std::string temp(s);
    return Reverse(temp);
}
ArkM 1,090 Postaholic

Alas, you got char codes instead of integers. Try to run your code with debugger...

const int NUMBERS = 5;
int tux4life()
{
    int num[NUMBERS];
    const int n = sizeof num/sizeof *num;
    cout << "Enter " << n << " integers: ";
    int i;
    for (i = 0; i < n && (cin >> num[i]); ++i)
        ;
    if (i < n) {
        cout << "Not enough numbers, bye..." << endl;
        return 1;
    }
    cin.ignore(1000,'\n');
    int number;
    cout << "Enter number to search: ";
    if (cin >> number) {
        for (i = 0; i < n && number != num[i]; ++i)
            ;
        if (i < n)
            cout << "Position " << i+1 << '\n';
        else
            cout << "Not found\n";
    } else {
        cout << "Not a number...\n";
        return 2;
    }
    cout.flush();
    return 0;
}
ArkM 1,090 Postaholic

He wants to input a calendar week number and get all dates within this week.
Calculating week #1 of a year is not trivial, as there are different algorithms how to determine the first week of a year from country to country.

It's a trivial task in C and C++: fill struct tm tm_year, tm_month and tm_day data fields (clear other fieelds), get its time value by mktime then get a new complete struct tm by localtime. The tm_wday member gets days since Sunday value.

For this locale number of week rules you can determinate number of week for every date: get day of week for January 1 then use difftime and old good modulo operator diif % 7 with some trivial calculations ;)...

However "array of dates" is not a complete specification.

ArkM 1,090 Postaholic

Hello i have an array of dates and want to input a week
ex week #14 and get all the dates written out in that week.

Anyone know a good way to convert weeks to dates or how i should solve this? thx for answer.

1. What's your "date"? You (and me) know that no such standard type in C++...
2. OK, you have an array of dates. And what did you want to do with these lots of dates?
3. a week ex week #14... What is it?...

ArkM 1,090 Postaholic

If every node was created via new Node construct, that's a Node destructor stub is:

class Node
{
public:
    ...
    ~Node() {
        for (all_branches) // pseudocode!
            delete ith_branch_ptr;
        // this node destruction
        // code (if any)...
    }
    ....
};

Now if the root is a pointer to the tree root node (or 0 for an empty tree), you can delete the tree by

delete root;
root = 0;
ArkM 1,090 Postaholic

The point of a singletone pattern is not a punishment the program for the second or third class instantiations. You must provide a program with one and only one object of a singleton class. So you present a stub of a singleton class implementation mechanics (one of possible ones) but this "declaration bomb" is not a good singletone class as such (especially with that barbaric exit)...
Look at:
http://sourcemaking.com/design_patterns/singleton/c++/1
http://www.infernodevelopment.com/singleton-c
http://www.codeproject.com/KB/cpp/singletonrvs.aspx
...

ArkM 1,090 Postaholic

1. Always use code tag for your snippets (aee this forum rules):
[code=c++] source

[/code]
2. It's a very bad code. Avoid C++ program termination by C library function exit(). It don't call destructors so you can't terminate the program gracely. Probably the only proper method is an exception raising,
3. What's a strange C++/C mixture code with deprecated <iostream.h> and printf...
4. Why return(0) ? Keep it simpler: return 0 . Don't ignore common practice: start you class names from the capital letter (Sample),,,

ArkM 1,090 Postaholic

Evidently it's impossible in terms of element access counter because no direct access to list elements so you need ~n/2 accesses to fetch a given number from a list - O(n) time complexity.

If n denotes a number of comparisons - it's the other story. It's so simple ;)...

PS. List or array? Array in the header, list in the body...

ArkM 1,090 Postaholic

Me >Have you ever seen the best free IDE - - MS VS 2008 Express?
You>>Ok, agreed with that Microsoft crap...
??? ;)

ArkM 1,090 Postaholic

Have you ever seen Windows API file access function sugnatures?

HANDLE CreateFile(
    LPCTSTR  lpFileName,	// address of name of the file 
    DWORD  dwDesiredAccess,	// access (read-write) mode 
    DWORD  dwShareMode,	// share mode 
    LPSECURITY_ATTRIBUTES  lpSecurityAttributes,	// address of security descriptor 
    DWORD  dwCreationDistribution,	// how to create 
    DWORD  dwFlagsAndAttributes,	// file attributes 
    HANDLE  hTemplateFile 	// handle of file with attributes to copy  
   );
BOOL WriteFile(
    HANDLE  hFile,	// handle of file to write to 
    LPCVOID  lpBuffer,	// address of data to write to file 
    DWORD  nNumberOfBytesToWrite,	// number of bytes to write 
    LPDWORD  lpNumberOfBytesWritten,	// address of number of bytes written 
    LPOVERLAPPED  lpOverlapped 	// addr. of structure needed for overlapped I/O  
   );
BOOL CloseHandle(
    HANDLE  hObject 	// handle of object to close  
   );

Besides that you must check up i/o function return codes, for example:

HANDLE fh;
fh = CreateFile(("\\Dat Files\\StartTime.dat",...);
if (fh == INVALID_HANDLE_VALUE) {
    // open failed
}
...
if (WriteFile(fh,...) == FALSE) { // use file handle
    // read failed
}
...
// don't forget to close opened file handle!
CloseHandle(fh);
ArkM 1,090 Postaholic

The MinGW is a native Windows port (without Cygwin) of the GNU C++ compiler. I think it's a good general purpose compiler. Both IDEs (Dev-C++ and Code::Blocks) use this compiler but the Dev_C++ is a frozen project - that's the long and the short of it.

>I know there's Code::Blocks, but I just find the program too heavy
Code::Blocks is too heavy!? Have you ever seen the best free IDE - MS VS 2008 Express?

Borland free compilers: no comments ;)

ArkM 1,090 Postaholic

>I'm not sure if C++ has this option
What an option? The C++ has no any options. It's a very powerful algorithmic language so you can invent any algorithm or data structure and implement it in C++ language. For example, your program case is a simplest array using example. What's a problem?

>c++ error C2086: 'myfile' : redefinition
Obviously, you declare myfile stream variable twice (or more). Close stream then reopen it for another file - that's all.

Next time use code tag properly:
[code=c++] source

[/code]
However your snippet was written in a very strange language, it's not the C++ ;)...

Apropos: you will never get exactly 518400 in the loop example (for floating point time).

ArkM 1,090 Postaholic

What is it - a file binarization?

ArkM 1,090 Postaholic

>i just found a bug with the coding.
Alas, you did not found a bug in this unpleasant, untidy code ;)
Next time use code tag properly:
[code=c++] codes...

[/code]

Well, cin >> string1 gets a single word only, not a line (see operator>> for std::string specification). For example, after the string1<Enter> the string1 value is "the" and the next input statement gets "string1". However the next input cin >> padN wants an integer but "string1" is not an integer and the cin input stream is in failed state now. No value for padN variable, it has undefined value after failed input. Probably, the program catch an exception when was trying to padd a huge or negative number of blanks...

getline(cin,string1); // get a whole line
cout<< "Please enter a number" << endl; // What's a number?
if (cin >> padN) { // OK, test padBlanks
    ....
} else { // bad input
    cout << "*** It's not a number" << endl;
    cin.clear(); // clear cin state
    cin.ignore(1000,'\n'); // skip bad input
}
... go on ...

Of course, the padBlanks function presented is a forged surrogate only. Have you ever seen my previous post? There is true padBlanks function body in the snippet.

ArkM 1,090 Postaholic

1. Next time use code tag:
[code=c++] source

[/code]

2. Alas, you forgot (;)) that case labels are constant expressions of integral (for example, an integer 123 or a single char 'x') or enumeration type. You can't type enumeration constants directly because no overloaded >> operator for enumerations.

Input text string then select month name by if statement cascade:

string month;
...
cin >> month;
int days;
if (month == "january")
    days = 31;
else if (month == "february") {
    // How about leap years?
    ...
} else if (....)
...
else { // Bad month name

}
...

3. Place system header include diectives in stdafx.h compiler generated files:

/// stdafx.h
...
#include <iostream>
#include <string>
...

Don't include them in your .cpp files. That's why you have #include "stdafx.h" VC++ compiler generated directive.

ArkM 1,090 Postaholic

Please, explain these evidently wrong statements:

pattern = new char*[size];
    pattern = p;

   ( pattern[i] = new char[length(p, i)] )= p[i];

See what happens:
- You create uninitialized array of pointers to char.
- The next statement overwrite a pointer to this array (memory leak) by the parameter p value.
- The 3rd statement is the most interesting because it do the same destructive performance in all-in-one manner: it allocates a memory chunk of undefined size (no check for length(...) <= 0) then save an obtained pointer value to pattern[i] element then (immediately) overwrite this value by p[i] . Thank God, the effect of "only even number of errors gets correct result" principle works: pattern and p pointers points to the same memory (see statements above ;)...

ArkM 1,090 Postaholic

>virtual means that the child class will inherit this member right?
Nope. The child class will inherit any member function(s) of its parent(s). You know (I hope) that it's possible to access objects of derived classes via pointers or references to the base class. When you call virtual member function in such a way, the "most derived" member function will been called.

I have declared saveMessage as a virtual because I hope that the "real" child of the class MsgSink implements its own saveMessage function to get and save correspondent argument. Moreover, I declare this function as a pure virtual (see =0 instead of the function body). Now derived (from MsgSink) classes must define this function to be concrete classes (i.e. have objects). A class with pure virtual function(s) called abstract class, it's impossible to instantiate it (impossible to define an object of this class). It's an interface (with derived classes) only. I want to define a proper message reciever interface then use it in class A. No matter who and where intercept my messages from class A object. In other words, the class A now is absolutely independed of the class B or any other class which will been derived from MsgSink abstract class.

About explicit keyword...
You may declare these constructors without explicit keyword. The C++ standard:

A constructor declared without the function-specifier explicit specifies a conversion from the types of its parameters to the type of its class. Such a constructor is called …

ArkM 1,090 Postaholic
if (padN > 0)
    string1.insert(0,padN,' ');

;)