Narue 5,707 Bad Cop Team Colleague

Could you describe the bug? I think I know what you're talking about, but simply giving an image with no explanation isn't terribly helpful.

Narue 5,707 Bad Cop Team Colleague

>I am not sure but if there could be any Tutoriouls about how interpreters is written..
Not that I know of off the top of my head, but I'm sure they exist. If you want an example, I wrote an extremely simple interpreter a while ago and posted it on Daniweb. You can find it here.

Narue 5,707 Bad Cop Team Colleague

I think it's time for you to discover the wonders of the tab key. Seriously, zero-width indentation is hard to read for everyone.

Narue 5,707 Bad Cop Team Colleague

Sounds like the low virtual memory notification. Kill as many unnecessary processes as you can and see if it goes away. You may need to clean up the programs that start automatically as well.

Narue 5,707 Bad Cop Team Colleague

>Would anyone be willing to see if you can tell me where my issue is.
That's simple enough. Your issue is here:

int i, j;

And it manifests here:

grid[i][j].row = i;
grid[i][j].col = j;
grid[i][j].frequency = 0;

i and j aren't initialized. Unless you get very lucky and your compiler automatically initializes local variables to 0, i and j are extremely likely to have garbage values that are well outside the bounds of your array.

Narue 5,707 Bad Cop Team Colleague

Infix notation is relatively difficult to parse. If you're doing this to learn how interpreters work, I'd recommend starting with a simpler syntax. For example, instead of "Number1 == 2", you could more easily parse "Number1 2 ==" (ie. postfix notation) with a simple stack.

Narue 5,707 Bad Cop Team Colleague

>he shouldn't insult me like that because knowing
>that word doesn't mean he is far better than me.
Welcome to the web. If you let losers like that bother you, you're better off staying in the real world where people are afraid of getting punched in the face for insults like that.

>Nature, your new avatar looks cool ^_^
Nature? ;)

Narue 5,707 Bad Cop Team Colleague

Wow, that guy looks like a lot of fun. What IRC server/channel was that in? :)

But yes, hacking can mean writing. There are multiple definitions of "hacking", and one of those is skillfully writing programs (or kludges, depending on the context).

Narue 5,707 Bad Cop Team Colleague

>I guess all I want to know is what kind of questions to expect.
Expect questions that test your knowledge and ability to do the job. I could list cookie cutter questions that aren't likely to be asked except by lazy interviewers, but that won't help you with the good questions, which will require you to think on your feet and actually understand what's going on.

In fact, even if you know the "answer" to a cookie cutter question, you might be asked to explain it. I do that occasionally to weed out the cheaters who try to get by on getting the answers to commonly asked questions. That's why I don't put much weight on the whole "know what to expect" thing, because even if you know what to expect, you still have to know your stuff.

Narue 5,707 Bad Cop Team Colleague

The interview is there to determine if you're suitable for the job. If you can't answer the questions to their satisfaction, you have no business working at that company. That's my advice, now if you want something more specific, ask a more specific question.

Narue 5,707 Bad Cop Team Colleague

strcpy is for C-style strings, not C++ string objects.

>How to solve it??
Change that line to this:

t_time = hr_str;
Narue 5,707 Bad Cop Team Colleague

OffsetX is a read-only property, so all you can do is get the value:

x = my_matrix->OffsetX;
Narue 5,707 Bad Cop Team Colleague

>does anyone know if there is a code in c++ that allows print on paper instead of monitor?
Communicating with specific hardware is outside the bounds of standard C++. If you want a good answer, you need to tell us what compiler you're using and your operating system.

scream2ice commented: thnx +1
Narue 5,707 Bad Cop Team Colleague

>So how can I create a pointer to function type if the
>function I want to call may be from different classes.
You'll need to think of another way to accomplish what you want. The short answer is that pointers to members don't allow you to do this because a pointer to a member is intrinsically bound to a single class. It helps to understand that pointers can hold more information than just an address.

Narue 5,707 Bad Cop Team Colleague

You first.

Narue 5,707 Bad Cop Team Colleague

If it's an exact match, you can use the Contains method from the string class. If it's more of a fuzzy match, you can use regular expressions with the Regex class.

Narue 5,707 Bad Cop Team Colleague

>I don't need a constructor or set functions because I don’t have any data members?
Huh? I'm not sure I understand where you're going with this. Your error was caused by a syntax problem. Removing the parentheses causes the code to work like you originally expected in that it creates an object of Temperatures and calls the default constructor.

Narue 5,707 Bad Cop Team Colleague

>Please, where I'm wrong?
You're mixing up pointers to functions and pointers to member functions. A pointer to a member function (which is what you want) must be called on an existing object:

MTP::Application obj;

(obj.*mExtVoid) ( true );
Narue 5,707 Bad Cop Team Colleague

>Temperatures degrees();
You stumbled on an annoying and subtle problem with C++'s declarations. What this does is declares a function called degrees that takes no parameters and returns an object of type Temperatures. Remove the parentheses:

Temperatures degrees;
Narue 5,707 Bad Cop Team Colleague

>What would be the syntax to insert say "hello" and say 3,3?

test.insert ( make_pair ( "hello",  map<int, int>() ) );
test["hello"].insert ( make_pair ( 3, 3 ) );

Don't forget that you need to create a new map for the second half of the pair.

>Also, how would I display the contents?

map<string, map<int, int> >::iterator iter = test.begin();

cout<< iter->first <<'\n';
cout<< iter->second[3] <<'\n';

Once again, remember that the second half of the pair is a completely separate map. iter->second gives you the map object, not an iterator.

Narue 5,707 Bad Cop Team Colleague

>What do you want to do?
My crystal ball says he wants to pass his C++ class without learning anything or expending any effort.

Narue 5,707 Bad Cop Team Colleague

>Works fine.
I'd guess one of the following:

1) iostream includes it somewhere along the line.
2) Your compiler is nice enough not to throw an error.
3) Your compiler is too old to conform to the C++ standard.

Narue 5,707 Bad Cop Team Colleague

>I wanted to know where will the selected message will be printed?
It's a part of the preprocessor, therefore it's a compile-time operation. Logically, you can expect the message to be printed in the compiler's output. In Visual Studio that's the output window (Ctrl+Alt+O).

>Can you give me a working example for it, and how it work...

#include <iostream>

#pragma message("This is a test")

int main()
{
  std::cout<<"Hello, world!\n";
}

This is in the output window (I've highlighted the message):

1>------ Build started: Project: Test, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>This is a test
1>Build log was saved at "file://c:\C++ Projects\Test\Test\Debug\BuildLog.htm"
1>Test - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Alex Edwards commented: That was a great example, I'll have to study the #pragma directive too +1
Narue 5,707 Bad Cop Team Colleague

>I'd be eternally grateful if someone could explain this in detail or point me to a good link?
Here's a good link, but the short answer is that due to floating-point imprecision, simply changing the order of arithmetic operations can affect the accuracy of the result.

Narue 5,707 Bad Cop Team Colleague

>Try--
>srand( time(NULL) );
How is that supposed to fix the incompatibility of time's return value with srand's parameter? By the way, 0 and NULL are identical in C++.

>try using time without ctime
Then the declaration would be missing.

>ctime has a function called time_t time ( time_t * timer )
>which most likely masks the time function defined in std
It's generally a bad idea to talk about things unless you have a clue. Seriously, I can't imagine where you pulled that explanation from.

Here's the real problem. time(0) returns a value of type time_t. srand takes a parameter of type unsigned int. The warning is saying that for the OP's compiler, time_t is a larger integral type than unsigned int and converting from the larger type to the smaller type may affect the value.

The easy solution is to use a cast to explicitly tell the compiler you know what you're doing and to shut the hell up:

srand ( (unsigned)time ( 0 ) );

But because of standard restrictions on time_t, you can't be sure that this will work in all cases (though I don't know of any systems where it will fail). The 100% correct solution is not to use time_t directly, but rather a hash of the value for seeding rand:

#include <climits>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <limits>

unsigned hash_time()
{
  time_t now = time ( 0 );
  unsigned char …
Narue 5,707 Bad Cop Team Colleague

>structs are left-over functionality from C
Structures are inherited from C, yes.

>classes are the object-oriented, C++ alternative
It's probably closer to say that Stroustrup prefers the class terminology and created something new to avoid breaking changes with the "C with classes" preprocessor. Lo and behold, that early decision gave C++ both classes and structures, for better or worse.

>a teacher of mine once said that structs are merely templates [...] for multi-type arrays
That's a rather dangerous explanation, because arrays support iteration while structures can have internal padding that would throw you into the realm of undefined behavior. I'd describe structures (in C) as templates for heterogeneous data records.

Narue 5,707 Bad Cop Team Colleague

1) You have more control over who accesses your data and how they access it. For example, let's say you have a telephone number in the class represented by a string.

If the variable is public, anyone can set it to anything. This means that your class can't assume the phone number to be valid at any given time and has to constantly validate it. It also means that if the number is invalid at a bad time, you have to figure out how to fail gracefully. This is messy and it makes your job harder.

Contrast that with if the variable is private and can only be accessed using your provided interface. You have a single location where the value is checked and errors are easy to throw. You also don't have to worry about the value elsewhere because the only way the it can be changed is through your interface, which guarantees that it's correct. It's cleaner, easier, and requires less effort on your part.

2) The only difference between a class and a struct is the default accessibility. If you have a class where the private members don't use or need the protection that private accessbility provides, you can use a struct and save yourself a bit of typing.

Narue 5,707 Bad Cop Team Colleague

Every function parameter is passed by value in C. Pass by value means that a copy of the value is made and you access the copy from within the function. For example:

#include <stdio.h>

void foo ( int bar )
{
  printf ( "%p\n", (void*)&bar );
}

int main ( void )
{
  int bar;

  printf ( "%p\n", (void*)&bar );
  foo ( bar );

  return 0;
}

The addresses are different. You can simulate the effect of passing by reference (that is, passing an alias for the actual object) with pointers, but pointers are still passed by value:

#include <stdio.h>

void foo ( int *bar )
{
  printf ( "%p\n", (void*)&bar );
}

int main ( void )
{
  int *bar;

  printf ( "%p\n", (void*)&bar );
  foo ( bar );

  return 0;
}

bar is a pointer, but the addresses are still different. That's because the bar from main and the bar from foo are two separate entities. At this point you have enough information to understand what's wrong in your code.

What happens is you pass a copy of the pointer to doSomething and then assign to the copy, but the original is still unchanged. The solution when you want to pass by reference is to simulate it with a pointer, even if the original object is already a pointer:

#include <stdio.h>

void doSomething ( char **string )
{
  *string = "some string";
}

int main ( void )
{
  char *origString = NULL;

  doSomething …
Ancient Dragon commented: Great explaination :) +31
Narue 5,707 Bad Cop Team Colleague

1) This looks like a perfect place to run a simple test on your own:

#include <iostream>

class Base {
public:
  ~Base() { std::cout<<"Base\n"; }
};

class Derived: public Base {
public:
  ~Derived() { std::cout<<"Derived\n"; }
};

int main()
{
  Derived d;
}

2) Sure, if you want an array of Base objects. If you want to be able to store both Base and Derived instances you probably want to use pointers to enable polymorphism. And if you're going to be using Derived polymorphically, I would recommend making your destructors virtual to avoid slicing.

Narue 5,707 Bad Cop Team Colleague

>How is that occurring, by adding an extra dimension to array it takes both words.
It helps to know that the native string type in C++ is actually an array of char, and cin's >> operator is pretty smart about knowing what types you give it. When array is an array of char, cin>>array[i]; will read a word into it. when array is a single char, cin>>array[i]; will read a single character into it.

Narue 5,707 Bad Cop Team Colleague

>Yeah I was referring to the difference between Unicode and ANSI chars ( wchar_t and char).
For the record, wchar_t doesn't imply Unicode. It's a generic wide character type that can be used by any number of character sets and encoding schemes that meet the requirements. And technically, char is only required to handle the basic character set which essentially consists of the lower half of ASCII (but not requiring the same values). Anything else to fill up the remaining characters is implementation-dependent.

In practice, correct string and character handling beyond ASCII is terribly complex because there are so many different sets of rules that need to be taken into account.

>What about the datatype __int8, is that guaranteed to be 8-bit?
That really depends on your compiler, as __int8 isn't a standard type.

Narue 5,707 Bad Cop Team Colleague

>you didn't hint on an answer to my original question.
It involves creating your own graphics and piecing them together manually. I'm not familiar with Qt, but it might give you the option of skinning your interface, which simplifies the piecing together part.

Narue 5,707 Bad Cop Team Colleague

>I think you're right on that one.
It depends on what you mean by "char". If you're talking about the char data type, it's always equivalent to one byte in C++, for whatever the definition of a byte is. I think Vernon is assuming that a byte always equates to an 8-bit entity, which is not true.

On the other hand, if you're talking about a logical character, such as with Unicode, then a single character could very well be represented by more than one octet[1].

[1] Which is the correct term for an 8-bit entity.

Narue 5,707 Bad Cop Team Colleague

>I tried to be as constant as possible... I got the following errors--
When I move around code, I do it for a reason. In this case, I moved the definition of mStruct outside of main because extern variables can't be initialized there. Oddly enough, your error says just that. :icon_rolleyes:

Here's some complete code for you to work with:

#include <iostream>

using namespace std;

struct MyStruct {
public:
  int x, y;

  MyStruct ( int first=0, int second = 0 )
    : x ( first ), y ( second )
  {};

  const int getX() const { return x; }
  const int getY() const { return y; }
};


class RestrictedTemplateClass {
public:
  template<const MyStruct &B>
  const static void displayParameters()
  {
    cout<< B.getX() << ", " << B.getY() <<'\n';
  }
};

extern const MyStruct mStruct ( 1, 2 );

int main()
{
  typedef RestrictedTemplateClass RTC;

  RTC::displayParameters<mStruct>();
}
Narue 5,707 Bad Cop Team Colleague

>Why is it that I cannot call th method in RTC::displayParameters() with
>the template-argument mStruct* when it is clearly a constant reference?
Because it clearly isn't. Let's start with the fact that <mStruct*> is a syntax error. The closest interpretation would be to call the instantiation of displayParameters using a pointer to mStruct. But mStruct isn't a type, and displayParameters doesn't even have a specialization that takes a type. So let's move that asterisk to a better location and work from your perceived problem:

const MyStruct * const mStruct = new MyStruct ( 1, 2 );

RTC::displayParameters<*mStruct>();

*mStruct is constant, but not the compile-time constant that templates require because you're using dynamic memory. But even if you remove that and make it a straight const object, it still won't work:

const MyStruct mStruct ( 1, 2 );

RTC::displayParameters<mStruct>();

Why? Because the local variable doesn't represent a compile-time constant either. To get a suitable constant object, the variable has to be non-local and have external linkage:

extern const MyStruct mStruct ( 1, 2 );

int main(int argc, char *argv[])
{
  RTC::displayParameters<mStruct>();
}

Furthermore, because the object has to be pretty darned constant, you need to specialize the template for that as well if you intend it to work:

template<const MyStruct &B>
static void displayParameters()
{
  cout << B.getX() << ", " << B.getY() << endl;
}

And of course, because the object is const, the member functions you use must be const as well:


       
Narue 5,707 Bad Cop Team Colleague

If you just want to use hash tables then the TR1 libraries are sufficient (assuming you have them). If you want to learn how hash tables work, then a good start would be this tutorial.

Narue 5,707 Bad Cop Team Colleague

>but can u just make the
>int x and int y public instead?
You can, but public data is typically a bad idea because it means you're giving full control over the values to everyone. Most of the time you don't want to do that, which is why public or protected member functions are used to give access without losing control.

Narue 5,707 Bad Cop Team Colleague

>I usually think of an "Expert Meanie"...
Well, I used to be an "Accomplished Meanie" until that whole TkTkorrovi episode. That pushed me well into the range of expert. :)

>In order to begin learning about Win32 and other programming languages
>for windows applications, I see C++ knowledge is a must.
The Win32 API has a strong foundation in C concepts, so even if you know C++, you'll find certain conventions to be awkward or even "unnatural" from a C++ perspective. MFC was designed as a C++ wrapper for parts of the Win32 API to fix that. I'd say that C knowledge is a must, but I say that for everything. ;)

>But after learning C++ is Win32 a completely different language with similarities.
Win32 is a library of functions and types that you can use from C++. And yes, it's very different, conceptually, from the basics that you're learning now, which likely uses a command-line interface.

Narue 5,707 Bad Cop Team Colleague

>i'm not so bad at picking out the experts and arrogant individuals either.
Which do you pick when an individual is both arrogant and an expert?

>do you mind telling me what the difference between a GUI and Application is?
A GUI is a type of interface for interacting with an application. Another interface type would be command-line. Others that come to mind might be an API or a domain specific language.

Narue 5,707 Bad Cop Team Colleague

Wow, this thread is all over the place, even compared with some of the tangents we get off on normally.

>I don't mind too much if others think I am dumb or anything as im LEARNING
Rest assured, we're generally very good at telling the difference between a beginner and an idiot. But also keep in mind that the programmers most qualified to help you around here are more likely to cut right to the chase and not sugar coat anything. You can find a good description of the "attitude" here.

Narue 5,707 Bad Cop Team Colleague

>I was asking for someone to point out there exists Win32!
Yep, that's immediately obvious from your original question of "What is C++ good for?". :icon_rolleyes: If I were to rate your question, it would be along with every other vague question that has no hope of getting an answer without a lot of dumb luck.

Narue 5,707 Bad Cop Team Colleague

>So your telling me what is being displayed on my windows
>screen is the output of a combination a C++ program?
I'm telling you that the Windows operating system is written in a combination of C and C++. Most of the programs you run are as well.

>but howwwwwwwwwwwwwwwwwww :O
Not to be rude or anything, but if you're as new to programming as it seems, you won't get it even if we told you. There's a lot of prerequisite knowledge that comes with understanding how non-trivial programs are written. As you learn more about programming and C++, you'll gradually come to an answer.

Narue 5,707 Bad Cop Team Colleague

>But I mean if I got a job which required C++ knowledge, what would they ask me to program?
You're not very quick, are you? If you get a job writing C++ code, and C++ can be used pretty much anywhere, then it stands to reason that they could ask you to write anything. It depends on what the job is. For example, I don't really expect anyone to ask me to write an operating system, because that's not in my job description.

>Can you name a specific program that used C++/C
>programming.... that people may be using everyday.
Windows, pick any version.

Narue 5,707 Bad Cop Team Colleague

>What are the PRACTICAL APPLICATIONS of C++ and even C for that matter.
Literally anything. Pick a program and it was probably written in some combination of C and C++, or written with a language that was implemented using C or C++.

Narue 5,707 Bad Cop Team Colleague

>we did not have the right team in place to answer customer inquiries.
Translation: "We hadn't yet hired someone to troll the web looking for threads discussing our company." :icon_rolleyes:

Salem commented: LOL +17
Narue 5,707 Bad Cop Team Colleague

I looked at your thread. Unless it completely breaks a rule (ie. no value whatsoever), we don't delete threads that have replies because it's unfair to those who have replied.

> I want to change my user name from "himajaasp" to "SRPH".
For that a PM to either cscgal or happygeek would be a good idea. They're the only ones who can make such a change.

Narue 5,707 Bad Cop Team Colleague

>Hey the Dude youre a maven here
The Dude is certainly a maven when it comes to posting arbitrary links in the Geeks' Lounge to entertain us. Beyond that, I'm not so sure.

Let's see:

>1. what happened
The Vista 32-bit display driver for my very expensive graphics card borked up at random intervals, corrupting the screen and causing my games to crash.

>2.how the problem rattled you
I play MMORPGs. Having the application crash while I'm in a group and the group ends up wiping because of me is rather bad for my in-game reputation.

>3.what you did to fix it
I haven't fixed it yet.

Narue 5,707 Bad Cop Team Colleague

>If i follow these i am almost a programmer?
You can't break down the practice of programming into a to-do list.

>if u know anything else please express here
Learn enough of a programming language to write a working program. Congratulations, you're a programmer!

Narue 5,707 Bad Cop Team Colleague
V1.insert ( V1.begin(), Model.begin() + StartModel, Model.begin() + EndModel );

Another alternative:

#include <algorithm>
#include <iterator>

std::copy ( Model.begin() + StartModel, Model.begin() + EndModel, std::back_inserter ( V1 ) );
Narue 5,707 Bad Cop Team Colleague

>I meant something like
That works, until you want a bigger triangle:

for( digit = 0; digit < 20; digit++ ) {
  // Uh-oh. Now you need to add 10 more cases
}

>But thanks anyways
For future reference, I despise any variation of "thanks anyway". It has extremely rude connotations.