deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but remember that without the flush or endl output manipulator, your output could be intermixed with output from other (background) processes

Thus why one should understand when and why flushing occurs automatically so as to know when to do it explicitly. The key lesson is that programming isn't a mindless activity. If you throw in endl, or any potentially unnecessary operation for that matter, "just to be safe" then that constitutes mindless programming and risks inefficient solutions.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The newline tokens will not flush the output stream.

And they likely don't need to do so. This particular statement strikes me as one of the following:

  1. Part of a prompt for input. After the prompt there will be a request, probably through a tied stream, and thus endl isn't required because the input stream will do a preliminary flush of tied output streams.

  2. An early line in a result report. There's little reason to flush until the report has been completed.

My recommended guideline is to prefer '\n' over endl except in cases where an explicit flush is absolutely needed and can be defended in a code review. Obviously this means that the programmer must understand when and where C++ will help you by flushing automatically.

Beginners can use endl as a crutch until properly learning the nuances of flushing, but too often that crutch is never abandoned.

Instead of the trailing "\n\n" tokens, it should be << endl << endl

At the very most, assumung a flush is required, only one endl or flush would be needed at the end. Otherwise you'd be flushing unnecessarily at least one time:

cout << "Concert4 Program Answers.\n" << endl; // Flush once, not twice
cout << "Concert4 Program Answers.\n\n" << flush; // More clear intentions?
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's syntactically incorrect since the string literal wasn't properly started, but otherwise the code is legit C++:

cout << "Concert4 Program Answers.\n\n";

What concerns in particular do you have about the statement?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I know this post is over 2 years old but I really hate it wen people post answers who don't know what they are talking about.

Me too. Especially people who bump posts with a strawman argument to prove that they know what they're talking about. Those are the worst. ;)

precompiled headers are NOT microsoftism

If you read carefully, you'll find that mention of Microsoftisms was made only once in reference to Visual Studio projects. If you want to read into it, the discussion is about stdafx.h and the Use Precompiled Headers option of Visual C++ specifically rather than precompiled headers in general. Last I checked, that particular implementation of precompiled headers is indeed specific to Microsoft's C++ compiler. Unless you were thinking of a compiler that can handle stdafx.h without explicitly building your own to make it work, I don't think calling it a Microsoftism is unreasonable.

they are part of C++ and will work on MS, Linux and anything else that compiles C++.

They're not part of C++ by my understanding of the ISO standard. However, compiler support is good. The problem is that compiler support is different, and therefore there are hoops you have to go through to port code written using precompiled headers to another compiler. Most of the time when someone asks about stdafx.h, they really have no need for precompiled headers in the first place, thus my recommendation of an empty project for portability sake.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It seems like you're asking for a browser that stops people from doing stupid things without any effort on their part. Sadly, that's not a reasonable expectation out of any software.

If you can recognize that a browser is little more than an interface into the web (a potentially unsafe source of data), and act accordingly, there's no problem. As an example, on any machine I've had unilateral control over I've never experienced security issues from browsers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Pretty much all you've got left in the big hitters is Safari.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes.

rubberman commented: Well put! :-) +12
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I figured it makes all the slots empty is that correct?

Presumably, yes. I take it you didn't write all of that code yourself?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The only obvious potential issue at a glance is this:

while (cWhoWon == '  '){

Your character literal is two spaces rather than one.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do you really want to terminate the program or just terminate the input process? The latter strikes me as more intuitive:

int main()
{
    int arr[0], i, sum = 0;

    cout << "Enter values: ";

    for (i = 0; i < 10; i++)
    {
        int input;

        if (!(cin >> input) || input == -1)
        {
            // Terminate input loop on -1 or input error
            break;
        }

        arr[i] = input;
        sum += arr[i];
    }

    if (i > 0)
    {
        // Only print the sum if a number was entered
        cout << "Sum is equal to " << sum << '\n';
    }

    getch();
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'am curious if it is possible and how to add drad & drop functionality to a window of an external application.

Only of the external application supports drag and drop, and you'd need to figure out how to make drag work between them. This strikes me as a tricky problem, given that drag and drop is internal logic. If the external application doesn't support it in the way you need, you're SOL. Ideally you'd have control over both applications' source code to tailor interaction between them.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so plz send me source code

No, do your own homework. If you have specific questions or problems, feel free to ask those, but Daniweb is not your personal cheating service.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There is no distinction between an array and a pointer this (1st) case.

Yes, that's close enough.

It looks like as if p is hidden array of pointers.

No, it's just a pointer. Since it points to the address of an item in an array, you can treat that pointer like an array to get other items. The concept here is that pointers give you largely unrestricted access to memory. If a char pointer (call it p) points to address 12345, you can use *(p + 1) to get the value at address 12346. Because array indexing is just syntactic sugar for pointer arithmetic, that means you can also say p[1] for the same effect.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

C99 concept of variable array is not accepted in Recent Compilers .They give errors like" Constant Expressions required in Function main on line 9"

Then you're not compiling as C99. The compiler also must support C99, which not all recent compilers do. Further, it looks like you're using Turbo C, which is not a recent compiler by any measure.

However, that said, I don't recommend this feature even if it's supported (for various reasons I won't elaborate on unless asked). I'd recommend using a pointer and dynamic memory allocation.

But after little modification Every thing went correctly by Initializing a dummpy value to an array and making it as global.

Your code is broken. At the point of the array definition, n is uninitialized, which invokes undefined behavior.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your code is still broken. A correct variation would be:

int a[2][3] = {{8, 9, 10}, {11, 12, 13};
int *p = a;

printf("%p\n", p[1]); // Prints the address of a[1]
printf("%d\n", *(p[1] + 1)); // Prints 12

p in this case points to the first row of a. It can be indexed to get to subsequent rows or using pointer arithmetic.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Possible, yes. We technically could extend Markdown to support this feature, but I suspect Dani doesn't want to lock us into a specific version of the libraries because that would make upgrades quite a bit harder to apply.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

does that equivalent to int *pa=new int[10];?

No. int* and int(*)[10] are two completely different and incompatible types.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What I meant to say is 'p' is declared as Pointer Variable and not Array of Pointers, so as to point to multiple variables.

A pointer is just a pointer. It points to a single entity of the declared type, but using pointer arithmetic can traverse over multiple entities if they exist. Is that what you're asking?

It works fine my friend.

"Works" and "correct" are two different things. Just because something works doesn't mean it'll always work. Predictable, portable behavior is the key for correctness.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

void Change_Address( int *&p, int *&pt)

That's C++, not C.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is there any place I can read more about this type mismatch.

Click Me.

It looks like as if p is hidden array of pointers and it is declared by default as p is assigned address of an array. Is it so ?

I'm having difficulty deciphering that question, can you rephrase it for me?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

*p=&a or *p=a will assign base address to p, which is equivalent to *p=&a[0].

Type matters, even if the addresses are all the same. *p = &a assigns a pointer to 2D array (ie. int(*)[2][3]) to a pointer to int, thus a type mismatch. *p = a assigns a pointer to a 1D array (ie. int(*)[3]) to a pointer to int, also a type mismatch. Only *p = &a[0] will do what you want, which is assign a pointer to int to another pointer to int.

So p[4] is same as *(p+4) ?

Yes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

*p=&a is a type mismatch if you want to flatten the array. Try *p = &a[0] instead. Also note that this trick isn't strictly portable due to how C restricts pointers walking past the end of an array. It'll work on every implementation I'm aware of though.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

malloc, realloc, and free. You have control over how much memory is used at any given point, but that control comes at the cost of managing allocations. The starting point would be:

char *p = malloc(4);
strcpy(p, "ABC");
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The last two would be recommended for not wasting memory. However, there are two questions that determine which you use, or if you want to go with dynamic memory allocation instead:

  1. Do you intend to modify the string?
  2. Do you indend to grow the string or is the size fixed?
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

She is referring to a local class, not a nested class.

Ah, my mistake. I read the question too quickly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Any solution to this problem other than separately evaluating expressions ?

Nope.

What does it mean by "all side effects of previous evaluations will have been performed, and no side effects from subsequent evaluations have yet been performed." ?

Side effects are things that happen beyond the direct result of the expression. As an example, a side effect of calling printf is that something gets written to the screen. A side effect of --a is that a gets decremented.

One of the reasons for sequence points is to have a consistent place at which you an say that side effects for an expression have completed. The canonical sequence point is the semicolon that terminates a statement.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But, dosen't post increment supposed to hold its concept for every kind of compiler ?

Yes. The problem is that the compiler can reorder and change expressions between sequence points however it wants as long as the defined behavior isn't affected. One possible ordering of c=(--a)+(--a); might be:

--a;
--a;
c = a + a;

Other equally rational orderings and changes are possible, which is why multiple updating side effects on an object in an expression is undefined.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Someone please point out where is loophole in my knowledge.

The missing link is sequence points and undefined behavior. In c=(--a)+(--a);, a is being modified multiple times between sequence points, which invokes undefined behavior. The compiler is under no obligation to do anything predictable.

Your second attempt removes the undefined behavior, and thus it works as expected and predictably.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can, but static data member definition isn't exactly intuitive without a fairly good understanding of the object model:

class outside
{
public:
      class inside
      {
      public:
            static int x; // Declare as normal
      };
};

// Define using name resolution
int outside::inside::x = 123;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Continuing milil's tangent, there are experts in the Java forum, for example. However, the questions on average are gradually becoming dumber, lazier, and a waste of time. So encouraging experts to participate more often should start with ensuring that quality questions are asked.

The problem is that this is difficult without introducing draconian policies that push non-experts away.

To the topic of this thread, I agree that Internet Marketing is spam bait. Maybe change the name, be very clear about the intention of the forum, and introduce the same moderation policy we have for the Viruses, Spyware and Other Nasties forum to ensure high quality. Anything that doesn't strictly conform to the posting policy gets deleted with extreme prejudice.

And if that doesn't work (ie. activity drops to nothing), kill the forum.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Because 10, 20, 30 does nothing more than evaluate to 30 due to how the comma operator works. 30 is an integer literal, which isn't compatible with a pointer to int unless you use a cast to make it an address:

int *p = reinterpret_cast<int*>(30);

This compiles, but it's not a meaningful address for the pointer.

On the other hand, a string literal internally is an array of const char and therefore compatible with a pointer to char. Note, however, that this compatibility is a historical artifact. To be strictly correct, the type of your pointer should be const char:

const char *str = "hello world";
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't really means what cloud computing really means.

It's nothing more than a marketing term for distributed computing. The internet is the quintessential cloud.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But what if unknown coder is smart enough to change hidden data of class?

Then unknown coder will be breaking the contract and if the hidden data of the class ever changes, will suffer the consequences of not strictly using the public interface provided by the class author. I see no issue here. It's like saying that people who know how to pick locks will be able to break into your house, and because of that, locks have no advantages.

To conclude with, is not OOPs a simple agreed process we are following which may or may not help to protect data?

As ddanbe said, data hiding is not data security. It's a strategy for hiding things the user of the class doesn't need to use the class, or for hiding implementation details that may change in future revisions of the class.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please elaborate on what these "errors" are.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

can you explain to me how the find_if works?

It works exactly like find, except instead of comparing against a value, it calls a predicate (in the form of a function, function object, or lambda). This gives you more flexibility in customizing exactly how you want the values in the vector to be compared.

I still dont understand it quite well

Will a definition help? find_if works like this:

template <typename InputIter, typename Pred>
InputIter find_if(InputIter first, InputIter last, Pred compare)
{
    while (first != last)
    {
        if (compare(first))
        {
            break;
        }

        ++first;
    }

    return first;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Two options. One is a verbatim string:

var query = @"select beggining_school,
end_school FROM Student,student_weekend,Weekend WHERE 
Student.ID=student_weekend.studentID AND 
student_weekend.WeekendID=Weekend.ID"

Note that indentation is significant in the string, as are newlines. The other, my preference, is literal concatenation because there aren't any "hidden" characters:

var query = 
    "select beggining_school," +
    "end_school FROM Student,student_weekend,Weekend WHERE " +
    "Student.ID=student_weekend.studentID AND " +
    "student_weekend.WeekendID=Weekend.ID"
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Isolated Storage. It's not completely protected from user access, but not as open as arbitrary files.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you find yourself naming variables with incrementing numbers, use a list:

List<Person> peepls;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

http://www.lysator.liu.se/c/bwk-tutor.html

Do you have anything specific you're interested in or just C in general.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Did you terminate your Salaried class with a semicolon?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

INLINE FUNCTIONS DON'T USE STACK. THEREFORE, EXECUTION TIME IS LESS.HOWEVER, THE STATEMENTS IN THE FUNCTION ARE SUBSTITUTED WHENEVER THE FUNCTION IS CALLED.INLINE FUNCTIONS ARE ALWAYS SHORT.

Many assumptions there, tamilselvi, and none of them are safe: http://www.gotw.ca/gotw/033.htm

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I can't figure out how to clear the "MathDep" - previous collection of items before importing the collection of items again.

MathDep.Clear()

Since you're using a hardcoded collection, you can just clear MathDep when you clear ListBox1.Items.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

int y = (a - b++)*--b;
int y = a-(b++ * --b);

Both of these still invoke undefined behavior. Parentheses won't save you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What are the contents of findNum? That's somewhat critical as to your results. However, it strikes me that you'd want to split it into two loops to get a more reader friendly output:

cout << "Positive: ";

for (int i = 0; i < num; i++)
{
    if (findNum[i] > 0)
    {
        cout << findNum[i] << ' ';
    }
}

cout << "\nNegative: ";

for (int i = 0; i < num; i++)
{
    if (findNum[i] < 0)
    {
        cout << findNum[i] << ' ';
    }
}

cout << '\n';
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes, it was off, the range is -128 to 127

You're still off. The standard doesn't assume two's complement, so the minimum required range is 127 to 127. Your limits.h header will be more specific to the hardware, so it's best to get these minimum ranges right from the standard document.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I understand that. What I want is an actual number that you expect on average, because that can affect the performance of your user control.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Only char has a guarenteed size, which is 1 byte with a range of -127 to 126.

Off by one. The guaranteed size is -127 to 127.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

manually I get the answer as 6 , but the compiler gives as -4 . how?

Because modifying a variable multiple times between sequence points is undefined behavior. The compiler can do whatever it wants. Further, upon invoking undefined behavior, the entirely of the program is henceforth undefined as well. So even if you get the result you want, that doesn't guarantee something else unrelated won't produce unpredictable results.

The fix is to move the expressions with side effects such that you get the result you actually want.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How many buttons on average are you generating?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

We use it at my company, but it doesn't get any more work done than the less "structured" methods we used in my previous position

Agile is a buzzword for a red tape process. The more red tape you have, the longer it takes to get shit done, regardless of the processes involved. Personally, I like Agile, but only use as little of it as possible to ease cooperation among the development team and end user. Any more than that and you're just slowing projects down with unnecessary crap.