Narue 5,707 Bad Cop Team Colleague

>I want to put an if statement to make sure that
>no letters are entered and only numbers are?
You can't control what the user types without delving pretty far into non-standard stuff. You'd essentially need to write your own shell code for handling raw input and the restrict echoing (and storage as well) based on the scan code.

Normally we stick to the standard error handling loop:

#include <ios>
#include <iostream>
#include <limits>

int main()
{
  int bottles;
  bool done = false;

  for ( ; ; ) {
    std::cout<<"How many bottles in the basket? ";

    if ( std::cin>> bottles )
      break;

    // Clean up the mess
    std::cin.clear();
    std::cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
    std::cerr<<"Invalid input\n";
  }

  std::cout<<"You entered "<< bottles <<'\n';
}
Narue 5,707 Bad Cop Team Colleague

You can't call a constructor after the object is created. By the time you get to class2's constructor body, myClass will already have been constructed. However, because class1 doesn't have a default constructor, this won't compile because there's no constructor to call. You can fix it by using an initialization list:

class2::class2(): myClass(5) {}

Also note that class2 myFinalClass(); is probably not doing what you think it's doing. It's actually a prototype for a function taking no parameters and returning an object of class2.

serkan sendur commented: i respect her knowledge so much +2
Narue 5,707 Bad Cop Team Colleague

>My question is: "Is array name a pointer (rather a constant pointer)"??
No, but the reality is similar. An array name is converted to a pointer to the first element most of the time. The official standard terminology is that an array name is converted to a pointer to the first element when used in a value context as opposed to an object context. A value context is when you're retrieving and subsequently using the value of an object, such as the right hand side of x = y; . An object context is when you're modifying or querying the object itself, not the value it contains. The left hand side of x = y; is one example.

People try to make sense of the array-to-pointer conversion rule by saying that the array is converted to a constant pointer, and that's why you can't assign to it or perform modifying arithmetic such as ++a . What really happens is that operators such as ++ see the operand in an object context, and those operators aren't defined for array types. The conversion is not made at all, so pretending that you're working with a constant pointer rather than an array is a fundamental misunderstanding.

There are a few places where an array can legally be used in an object context, which is why saying an array name is a pointer is wrong. Two of the common places an array is used in object context are:

  1. As an …
me_ansh commented: Was an eye opener +1
Narue 5,707 Bad Cop Team Colleague

>but for simple cases (just like this one, where all it is doing is
>storing a number), it's not bad practice to just make it public?
It depends on whom you ask this question. Some people will tell you that public data is absolutely evil. Others will tell you that it's okay sometimes, but you should avoid it.

In the usual case, accessors and mutators break encapsulation anyway because 99% of them consist of a member function wrapper around an unchecked access of the data member:

T KewlClass::GetX() const
{
  return x;
}

void KewlClass::SetX ( const T& value )
{
  x = value;
}

This clearly defeats the purpose of data hiding and the only way it's better than public data is future-proofing. You can decide to later change the implementation so that more checks are performed or something completely different happens, all without altering the interface.

Personally, I think that an excessive number of accessors and mutators is indicative of a design flaw. You should be focused more on the object itself, and how the object behaves as a whole, not the individual members of a class. This is why good OO design is so hard; a good interface is not nearly as simple as the tedium of a slew of accessors and mutators.

Narue 5,707 Bad Cop Team Colleague

>written by dileep basam ..
Holy crap. Okay, I guess correcting your errors will take a long post. :icon_rolleyes:

>main()
Let's get one thing straight. What you're doing is called implicit int. It means that if you don't supply a type where one is expected, int is assumed. If your compiler allows you to do this (implicit int was removed in C99 and will no longer compile), don't forget that the two following definitions of main are exactly the same:

main()
int main()

In other words, both are defined to return an int, and failing to return an int is undefined behavior. Your definition of main displays one of the biggest problems with implicit int, and that's the mistaken assumption that not providing a return type means there is no return type and no return value is needed.

There are two correct ways of defining main:

int main ( void )
int main ( int argc, char *argv[] )

The portable return values are 0 and EXIT_SUCCESS (defined in stdlib.h) for success, and EXIT_FAILURE (also defined in stdlib.h) for failure. Anything else that's not directly equivalent to the above is incorrect.

>int i,counter=0,flag=0;
>char uid[25],pwd[25],s_uid[][25]={"11user1","12user2","13user3"};
>char s_pwd[][25]={"Pwd1","Pwd2","Pwd3"},ch='a';/*dummy character in ch */

Stylistically this is very poor because it makes reading your code more difficult. Don't sacrifice readability for perceived brevity, it's a cheap tradeoff, and that's why most style guidelines will tell you to limit yourself to only …

William Hemsworth commented: Good clear post :] +6
Narue 5,707 Bad Cop Team Colleague

There are two forms of getline that concern you in this case. The first is a member function of cin:

char buffer[BUFSIZE];

cin.getline ( buffer, sizeof buffer );

Note that the argument is an array of char, and the maximum number of characters you want to fill it with. The second is a non-member function for the std::string class:

string bufferl

getline ( cin, buffer );

You're mixing those two up by passing a std::string object to the member function, but no such overload for std::string exists. Thus, you need to use the non-member function if you want to continue using the std::string class:

bool enterPlans(RememberPlans& nds)
{
    cout << "This program creates lesson plan documents.\nType export to view and export the the plans.\n\n";
    cout << "Enter subject: ";
    getline(cin, nds.subject);

    if(nds.subject == "export" || nds.subject == "EXPORT")
    {
        return false;
    }

    cout << "\nEnter date: ";
    getline(cin, nds.date);

    cout << "\nEnter resources (seperate with '-'): ";
    getline(cin, nds.resources);

    cout << "\nEnter a brief descrition: ";
    getline(cin, nds.description);	

    cout << "\n";
    system("CLS");

    return true;
}
Narue 5,707 Bad Cop Team Colleague

fopen doesn't support formatting specifiers. You need to build the string manually before passing it to fopen:

#include <stdio.h>

int main ( void )
{
  char filename[24];

  if ( scanf ( "%19s", filename ) == 1 ) {
    FILE *out;

    strcat ( filename, ".txt" );
    out = fopen ( filename, "w" );

    if ( out != NULL ) {
      /* Write to the file */

      fclose ( out );
    }
  }

  return 0;
}
Lord Prime commented: very helpful +1
Narue 5,707 Bad Cop Team Colleague

>good method for swapping the numbers.
No, it's not. It's brittle, often slower than the conventional method, and due to compiler optimizations the chances that it saves memory over the equivalent swap with a temporary are actually quite slim. This trick may have been useful twenty or thirty years ago, but now it's just a stupid way for stupid people to show of their knowledge of stupid trivia.

Freaky_Chris commented: Agreed +4
Salem commented: Well said +17
Narue 5,707 Bad Cop Team Colleague

I don't know what's more pathetic. The fact that you're so unethical that you would even have this kind of business practice, or the fact that you're recruiting for equally unethical people on the very forums you intend to troll with your spam.

Salem commented: Well said, well said! +27
Rashakil Fol commented: Poorly said, poorly said! +7
Narue 5,707 Bad Cop Team Colleague

What you asked for, by my reading, is an array that grows automatically to fit whatever index you provide. So if you say int array[], then try to index array[100], the array will resize itself to have 101 elements.

You can do this with dynamic arrays and such things as the std::vector class, but managing the size is still somewhat manual. You can wrap it in a class though, and abstract the work away into a nice convenient syntax (expand to suit your tastes and standard container rules):

#include <iostream>
#include <vector>

template <typename T>
class auto_vector {
  std::vector<T> _base;
public:
  typedef typename std::vector<T>::size_type size_type;
public:
  auto_vector() {}
  auto_vector ( const std::vector<T>& init )
    : _Base ( init )
  {}

  size_type size() const { return _base.size(); }

  T& operator[] ( size_type i )
  {
    if ( _base.size() < i )
      _base.resize ( i + 1 );

    return _base[i];
  }
};

int main()
{
  auto_vector<int> v;

  v[10] = 12345;

  for ( auto_vector<int>::size_type i = 0; i < v.size(); i++ )
    std::cout<< v[i] <<'\n';
}

Other languages have tried this with their built-in array type, and it's generally accepted to be a bad idea because indexing bugs can remain hidden often with no more of a symptom than wasted memory.

StuXYZ commented: Nice STL extend and then pointing out why it is such a bad idea !! +3
Narue 5,707 Bad Cop Team Colleague

>What I meant by that is the fwrite() function (binary writing)
>is a lot faster than fprintf() (text mode writing).
I see. However, I don't like the distinction you're making. I prefer to think of it as unformatted vs. formatted[1] rather than binary vs. text. This fixes one of the more common misconceptions that, for example, fread/fwrite can't be used on text streams.

[1] The standard separates the I/O functions into formatted (printf, scanf, etc...), character (getchar, putchar, fgets, puts, etc...), and direct (fread and fwrite). Formatted directly supports varying types, character supports characters and strings, and direct supports block I/O through generic pointers.

Ancient Dragon commented: good point :) +36
Narue 5,707 Bad Cop Team Colleague

>Does there even exist a harem series which you like or are you still
>waiting for an ideal one to come along? ;-)
Ouran is good. Hana Yori Dango is good. Otoboku is good. I'd probably say Shuffle! is decent too if pressed. ;) There are a few shiny rocks amonst the turds when it comes to the harem genre.

Generally harem series make you so frustrated with the stupid behavior of the characters that you can't keep watching, or they're so full of ecchi that even an undersexed teenager would say "WTF?!".

>I, My, Me - Strawberry Eggs revamped?
I'm thinking it'll be more of a darker, angsty Otoboku.

John A commented: Thanks for the harem recommendations. I'll definitely watch them. +17
Narue 5,707 Bad Cop Team Colleague

Perhaps you should try to learn about trees in general. Most people start with linked lists to get a feel for how linked data structures work, then they move on to binary search trees, and then to graphs. Generally if you understand binary search trees, it's not a great leap to prefix or suffix trees.

Another point of research might be searching theory. If you understand several of the common search algorithms, you can more easily digest the details of a suffix tree as the concepts will be more familiar.

Narue 5,707 Bad Cop Team Colleague

>A much clearer method would be rand()%x , where x is the number you want.
Clearer, but not necessarily better. rand has subtleties that need to be considered. In particular, there are two distinct problems with rand: one historical and one that is still common.

The historical problem is that older implementations of rand (and extremely poor modern implementations) show a pattern where the low order bits of the random number are decidedly nonrandom. Because the remainder trick ( rand() % N ) uses the low order bits, it fails miserably for smaller values of N.

The solution for the historical problem is to use the high order bits instead with some variation of division by RAND_MAX ( rand() / ( RAND_MAX / N + 1 ) ). If you have a small value of N and a weak implementation of rand, this method is vastly more effective.

The second problem is one of distribution. Both of the above methods (remainder and division by RAND_MAX) have the same problem with distribution, regardless of the quality of rand. Because implementations of rand have pretty much been fixed, the historical problem isn't much of a problem anymore, but the problem of distribution is still present. Except in very specific exceptions, some numbers will be produced with a higher frequency than others because rand is designed to return values in a certain range, and if you close that range then the pigeonhole principle is in effect and …

iamthwee commented: For not shamelessly plugging your rather cute website! +17
Narue 5,707 Bad Cop Team Colleague

>template<class Tpl, unsigned int iSize>
>void AddData(CClient& c, CArray<Tpl,MAX_SIZE>& ar)
Change MAX_SIZE to iSize. Since you didn't have iSize anywhere in the parameter list or as an explicit list in the instantiation, your compiler couldn't figure out what it was supposed to be.

Frederick2 commented: helped big time! +1
Narue 5,707 Bad Cop Team Colleague

>string a;
This is an empty string.

>a= tmp;
a doesn't exist. a is still an empty string. The subscript operator does not change the size of a collection.

freelancelote commented: Thanks a lot. +1
Narue 5,707 Bad Cop Team Colleague

>I can cout the string literal by just stating the
>name of the object or I can use the data function.
Yes to the first part, no to the second. You can "cout the string" by passing just the string object, but it's not safe using the data member function because the data member function doesn't guarantee that the returned string is null terminated. If you change data to c_str, then it's safe.

That's the difference, by the way. c_str returns a null terminated C-style string, data returns a pointer to the first item in an array of characters (which may or may not be null terminated).

freelancelote commented: Thanks a lot. +1
Narue 5,707 Bad Cop Team Colleague

>all right, i will take note of your advice.
>anyway,
Anyway, you clearly didn't bother to fully read and comprehend my previous post because my advice included a fix for your immediate problem.

>i just want to know why it does not work when
>i get the user to specify the file path instead.
Because you're doing it wrong. You're also comparing two different pieces of code as if they were the same. Here, look:

// This is what happens when you manually specify the name
// Note that I fixed your habitual syntax error by adding quotes
infile.open("C://cars.txt", ios::in);
// This is what happens when you use the string object,
// based on the exact contents of the string
infile.open("\"C://cars.txt\"", ios::in);

In the second example you're trying to open the file called "C://cars.txt", where the quotations are a part of the name. That's not the case on your file system, so the specified file does not exist. Is that clear enough for you?

And for future reference, you don't need to play games with double (back)slashes with input. The only time where a backslash makes a difference is in a string literal, where the backslash introduces an escape character:

const char *filename = "C:\file.txt"; // Wrong!

Since one backslash is an escape character, you need to use the escape character representing a backslash, which is two backslashes:

const char *filename = "C:\\file.txt"; // Correct

This doesn't apply to forward …

Luckychap commented: Simple great! +3
Narue 5,707 Bad Cop Team Colleague

The nice thing about pseudocode is that you make up the rules. Most real languages do allow what you want, though, so you're not really deviating from common use.

Run.[it] commented: Cheers, top work as always! +2
Narue 5,707 Bad Cop Team Colleague

>well i aint got any c books
I would have more sympathy for you if the internet weren't a wealth of information. Yet you've bypassed all of the tutorials, references, and ebooks that are available, and gone with the worst possible first step: bothering other people with an easily researched question. Here, let me google that for you since you've already bothered me.

>what can i use then then
fgets. While you're googling, why not look up why gets is unsafe.

>as my tutor was recommending the "gets" statement?
And get a new tutor. Your current one is just clueless enough to ruin your future as a C programmer.

devnar commented: "let me google that for you"- Cool site :) +1
Narue 5,707 Bad Cop Team Colleague

So you want to populate the board with random numbers in the range of [0, 18) and disallow more than two of a kind? I'd say use a frequency table for the range since it's small, and repeat getting the random number until you find one that doesn't go beyond the limit:

#include <cstdlib>
#include <iomanip>
#include <iostream>

int main()
{
  using namespace std;

  int board[6][6];
  int freq[18] = {0};

  for ( int i = 0; i < 6; i++ ) {
    for ( int j = 0; j < 6; j++ ) {
      int r;

      do
        r = rand() % 18;
      while ( freq[r] >= 2 );

      ++freq[r];
      board[i][j] = r;
    }
  }

  for ( int i = 0; i < 6; i++ ) {
    for ( int j = 0; j < 6; j++ )
      cout<< left << setw ( 3 ) << board[i][j];
    cout<<'\n';
  }
}

The frequency table holds a count of all of the values in your range.

Alex Edwards commented: Wow! O_O +5
Narue 5,707 Bad Cop Team Colleague

>char* word; /* Temporary holding for each word */
>fscanf(fin, "%s", word);
Pointers aren't magic containers for infinite data. You need to allocate space to word before you can write to it. In this case, there's little point in using a pointer unless you want to get fancy with single character reads.

>arts[index] = (char*)malloc(strlen(word) * sizeof(char));
You cast the result of malloc in one call but not another. Consistency is more important than perfect style, but I'd still recommend removing the cast. Also, instead of sizeof(char) , you can get the same effect without specifying the type directly using sizeof *arts[index] . Also note that sizeof(char) is guaranteed to be 1.

Finally, when allocating memory for a string, you need to add an extra slot for the null character. If you don't do that, you'll end up with problems later when overflowing the buffer.

Try this:

void populateArts(char **arts, FILE *fin, int *numArts)
{
	int index;
	char word[BUFSIZ]; /* Temporary holding for each word */
	
	arts = malloc(*numArts * sizeof *arts);
	
	fscanf(fin, "%s", word); /* Skip over category */

	/* Fill articles array */
	for(index = 0; index < *numArts; index++)
	{
		fscanf(fin, "%s", word);
		printf("word is %s\n", word);
		
		arts[index] = malloc(strlen(word) + 1);
		strcpy(arts[index], word);
	}
}
Narue 5,707 Bad Cop Team Colleague

>I figured I'd use something like an array to hold the points
Since this is a graph problem, so you need to hold the identity of the vertex (A, B, C, etc...), the the vertices that a vertex is connected to through an edge (A->B, A->C, B->C, etc...), and the weight of the edge (B->C=31, A->B=4, C->D=3, etc...). As long as you can represent all of that information, it really doesn't matter how you handle the storage. However, an adjacency matrix or adjacency list would be a good start, if you've studied those at this point.

>Then I figured you'd use a stack to keep track of the direction you went
Sounds good to me. You can also treat this as a more sophisticated find_min algorithm. When you find a path that's smaller than the current path, make a copy of the stack and the total weight so you can print the result:

stack<Vertex> min;

for (int i = 0; i < n_paths; i++ ) {
  // The magic is in weigh_graph ;-)
  stack<Vertext> curr = weigh_path ( graph, i );

  if ( min.empty() || weight ( curr ) < weight ( min ) )
    min = curr;
}

show_path ( min );

To help you do research, this is called the single pair shortest path problem. Several good algorithms already exist for solving it, but this assignment may be to get you to come up with something on your own.

DemonGal711 commented: Very helpful. Addressed my questions rather then given a general help solution. I would prefer more people do this since, normally, the questions people ask are opinions rather then something you can get from a book. +1
Narue 5,707 Bad Cop Team Colleague

>So does making it = 0 make it pure virtual?
Sadly, yes. It's terribly obscure and clever on the part of C++'s designers (much like destructors being the constructor name with a leading tilde), which is a shame.

>So basically it doesn't like me creating new types of Account.
Classes that derive from Account must override the pure virtual member functions in the derived class. If you don't, the derived class inherits the abstract status. You say Account is abstract, so it should have at least one such member function, yet your CurrentAccount class only defines a constructor.

Lokolo commented: Uber helpful. +1
Narue 5,707 Bad Cop Team Colleague

find_if returns an iterator to the matched item, and for_each is retarded. ;)

CTest *it = b;
CTest *end = b + 150;

while ( ( it = find_if ( it, end, myCountIf ) ) != end ) {
  it->Set();
  ++it;
}
Alex Edwards commented: Excellent! =) +5
Narue 5,707 Bad Cop Team Colleague

>malloc() always returns a void pointer. You need to typecast it.
C is kind enough to implicitly convert to and from pointers to void without the need for a cast. In fact, if you get into the habit of casting the result of malloc, your code is both more prone to subtle errors and harder to maintain.

The recommended way to use malloc is as follows (assuming a pointer called p is declared):

/* Allocate one item of the type p points to */
p = malloc ( sizeof *p );

/* Allocate N items of the type p points to */
p = malloc ( N * sizeof *p );

Notice that all of the type information is acquired dynamically rather than being hard coded.

Narue 5,707 Bad Cop Team Colleague

>Here is my constructor.
Is that the whole of your constructor? If so, it's not accomplishing much of anything as you allocate memory to the local variable EmpPointer, and then proceed to leak memory when EmpPointer goes out of scope at the end of the constructor.

William Hemsworth commented: Awesome avatar :) +5
Narue 5,707 Bad Cop Team Colleague

>Please explain me briefly.
I believe the customary response to such a lazy question is "Do your own damn homework!".

Narue 5,707 Bad Cop Team Colleague

Oracle is a database.

Rashakil Fol commented: Are you sure? +7
Narue 5,707 Bad Cop Team Colleague

The vector class is in the std namespace. Change vector<FrequencyNode> list; to std::vector<FrequencyNode> list; . You have other errors though.

Narue 5,707 Bad Cop Team Colleague

>That confuses me =(
Get used to it. Good programmers are in a constant state of confusion. What I mean is that std::string can be used as a first-class type just like int. However, because they're different types, they have different usage patterns.

>Is the main significance with using the string class the i/o functionality then?
Nope, the significance of using the string class is being able to use strings. :icon_rolleyes: The significance of int is that you can do integer math, which is somewhat more difficult using strings. I/O works with both, fortunately.

clutchkiller commented: rofl +1
Narue 5,707 Bad Cop Team Colleague

>but (as I've read) pointer arithmetic is faster
Prove it. In your example, the two are quite likely compiled to exactly the same machine code. Array subscripting is literally syntactic sugar for the equivalent pointer offset calculation. A more likely example is this:

int x[N];
int *p = x;

for ( int i = 0; i < N; i++ )
  process ( x[i] );

for ( int i = 0; i < N; p += i )
  process ( *p );

The latter could very well be faster (though I would question why you're worried about such micro-optimizations) due to the fact that the body of the loop is only performing a dereference rather than an addition and a dereference.

My advice is not to worry about it. Use whichever more clearly displays your intentions.

Alex Edwards commented: Nice example! =) +4
Narue 5,707 Bad Cop Team Colleague

>Name:
Julienne Walker

>Position:
Team Leader

>Company:
I choose not to say.

>1. What are the functions of your industry and profession?
I'm in the field of creating developer tools, specifically compilers, libraries, and the like.

>a. What is your title? how long have you been in this position?
I'm a team leader, and I've been in this position (or a similar position) for about ten years.

>b. How did you become interested in this field?
An unhealthy fascination with data structures.

>c. What are your responsibilities, and what skills
>are particularly useful to you in fulfilling them?
I train, hire, manage a team of developers, and handle senior level programming tasks. People skills and a strong foundation in the business aspects of the field are both extremely helpful.

>d. What is a typical "Chain of command" in this field?
Junior developer -> senior developer -> project leader -> team leader -> manager is a rough description.

>e. How does your organization compare with others in the field?
We're concentrated awesome.

>2. What does your workday consist of? your work year?
Meetings, helping co-workers, and not nearly as much coding as I'd like.

>a. How many hours a week do you work?
40 to 60.

>b. Do you work closely with other people?
Yes.

>c. What are some problems you must face, and decisions you …

dickersonka commented: nice gesture to help +2
Rashakil Fol commented: Naryu +7
Narue 5,707 Bad Cop Team Colleague

>but you're rude whenever you feel like it
I'm appropriately rude. If you're rude to me, don't expect me to be nice to you.

>One of the rules of this forum is "keep it pleasant".
Not only am I quite familiar with the rules, I'm in the unique position of having the final say on their interpretation.

>You are not following that rule.
The key phrase in Keep It Pleasant is "malicious intent", which is the deciding factor in enforcing this rule. If it's determined that there's no malicious intent, even rude posts are more likely to be allowed than not. As such, I don't feel I've broken that particular rule. However, as it appears you've reported my post, I'll step aside and allow the rest of the mod team make an objective decision. Thank you, by the way, for reporting posts you feel cross the line regardless of who the author is. Nobody is exempt from following the rules.

>It's sad how a relatively simple skill like programming can go to a simpleton's head.
If you think programming is simple, you clearly haven't done much of it.

>Don't bother to respond; I won't read it.
I don't believe that for one second. If you're egotistical enough to scold me for not being nice when it has nothing to do with you, you're egotistical enough to be interested in my reply.

To be honest, I was half expecting your IP …

Narue 5,707 Bad Cop Team Colleague

>However, this one of my attempt, please give some suggestion.
The usual pattern is a loop for the rows and two loops inside of it, one for the leading spaces and one for the triangle body:

for i = 0 to N
    for j = 0 to nspace
        print ' '
    for j = 0 to nbody
        print 'X'

From there it's simply a matter of getting the expressions right for calculating nspace and nbody.

Or you can just turn in something that will shut your teacher up, like this:

#include <iostream>

int main()
{
  for ( int i = 0; i < 32; i++ ) {
    for ( int j = 0; j <= i; j++ )
      std::cout.put ( ~i & j ? ' ' : '1' );
    std::cout.put  ( '\n' );
  }
}

;)

chococrack commented: ran the pyramid code cause i wasn't following it, had a great laugh ty +1
Narue 5,707 Bad Cop Team Colleague

>was wondering if anyone else does
Pokemon is like watching porn. Everyone who does it will vehemently deny it when the topic comes up. As such, don't expect your Pokemon hacker peers to step forward. :D

William Hemsworth commented: heh :) +4
Narue 5,707 Bad Cop Team Colleague

>Why is there assembly code for the string class of C++?
On your implementation, you mean. The answer is probably optimization, especially if you read the code and understand what the algorithm is trying to achieve.

>How can you be sure the listing is how the C++ compiler designers implemented it that way?
I'd say that code is hand crafted, or it's tweaked assembly output. Either way, the implementation is extremely low level and clearly written with performance in mind.

Alex Edwards commented: Yes, I meant for my implementation. Thanks for the correction =) +4
Narue 5,707 Bad Cop Team Colleague

The classic solution is a union, but you can't have a union of points unless the Point class has a trivial constructor.

Another option is to store objects of a proxy class instead of storing Point objects directly. The proxy class will handle the disconnect between objects and pointers, and your Triangle class can largely ignore it.

You can also make your Triangle class a template class and then have a pointer specialization, but that's really just a cute way of having two separate classes in this case. ;)

Alex Edwards commented: I like option #2 =) +4
Narue 5,707 Bad Cop Team Colleague

>I was wondering if anyone has used this book
Yes, though you've discovered independently that it's not suited for beginners.

>any recommendations for books that might be easier to understand
Accelerated C++ by Andrew Koenig and Barbara Moo. This book is designed for beginners and covers roughly 90% of the language that you'll find yourself using regularly.

Alex Edwards commented: Yeah! The C++ Programming language is totally a reference book and not a beginners tutorial @_@ +4
Narue 5,707 Bad Cop Team Colleague

>well if its so hard to make graphics then why is it the most used proggraming language?
Presumably you mean why is it the most used language for games. A lot of C++ (most of it, I would wager) is written without the need for graphics. But to answer your question, there are two pretty obvious reasons:

  1. There's a great deal more to choosing an implementation language than how easy it is to make pretty pictures.
  2. Game developers tend to be both talented and experienced, and they focus on such things. Much like writing compilers is "mind bendingly hard in C++" for the average programmer, those of us that work in the field aren't nearly as intimidated.
jbennet commented: well said +31
Narue 5,707 Bad Cop Team Colleague

>How can i delete a particular element using delete operator?
Can you be more specific? A vague question produces vague answers, or completely off-the-wall answers as exhibited by the previous reply.

Alex Edwards commented: Whoops, I took that literally X_X +4
Narue 5,707 Bad Cop Team Colleague

>You don't seem to have neither a namespace nor a class defined, both of which are needed.
A namespace isn't required, but for obvious reasons at least one class is.

scru commented: You are right. +4
Narue 5,707 Bad Cop Team Colleague

>Is it possible to some how tell the compiler to use
>these symbols even if they aren't in ASCII?
You need to specify what you mean by "tell the compiler". Of course you can write code to make use of different character sets, but it's not as trivial as using the basic character set (which is itself a subset of ASCII in terms of the available character glyphs). There's a whole field of research and development covering that practice, called internationalization and localization. You can also write characters outside of the basic character set directly in your source code if the compiler and text editor support them. So the answer to your question is yes, as with pretty much any "is it possible?" question you can come up with.

Alex Edwards commented: Whoo! I didn't know custom and foreign characters were a part of a field of study O_O - good info! =) +4
Narue 5,707 Bad Cop Team Colleague

>Maybe 6000 pages is overkill @_@
Ya think?

>but I still want to make a book with a fair amount of content! =)
Figure out what you want to say, then say it. If you focus on the quantity of content, you'll end up with lots of filler that nobody cares about. What you really want to do, what good technical authors do, is take a mass of information and describe it in such a way as to make it accessible without losing the important parts.

My goal in writing tutorials is to save you the time and effort in searching all over creation for information by collecting it in one place, and also to save you the time and effort in understanding it by describing it in a clear, concise, and consistent manner[1]. That should be your goal as well, from what I can tell by your description of the project.

[1] I can't say I've succeeded, but that's my goal.

Alex Edwards commented: Will do! =) +4
Narue 5,707 Bad Cop Team Colleague

Well then...best of luck.

Alex Edwards commented: Thank you!!! =) +4
Narue 5,707 Bad Cop Team Colleague

>using namespace std; // out of place
Actually, that's a better place than your proposed solution. The effect of a using directive is limited by scope. When you restrict the directive to a block scope, you minimize the chances of a name collision and effectively remove the biggest reason for avoiding the using directive[1].

>// C++ arrays start with index 0, so its 0, 1, 2, 3, 4
I think it's safe to say that the OP already understands this. :icon_rolleyes:

[1] The reason: a using directive at global scope defeats the purpose of namespaces. The only reason you should have a using directive at global scope is when porting pre-standard C++ quickly. In new code, it's a bad practice.

chococrack commented: Thank you very much for the feedback +1
Narue 5,707 Bad Cop Team Colleague

I'd be willing to bet that it's the string literal causing you problems. Try this:

#include <windows.h>
#include <iostream>

DWORD WINAPI MyThreadFunction( LPVOID lpParam );

int main()
{
  DWORD   dwThreadId;
  HANDLE  myThread;
  char *param = "HELLO";

  myThread = CreateThread(
    NULL,
    0,
    MyThreadFunction,
    param,
    0,
    &dwThreadId);

  while(1){
    Sleep(3);
    std::cout << "main";
  }
  std::cin.get();
  return 0;
}

DWORD WINAPI MyThreadFunction( LPVOID lpParam )
{
  std::cout << lpParam;
  while(1){
    Sleep(10);
    std::cout << "thread";
  }
  return 0;
}
Narue 5,707 Bad Cop Team Colleague

Labels don't introduce a new scope. This error tells you that jumping into the switch can (or does) ignore the definition of the object even though it's still in scope. I'm sure you can imagine what would happen if you try to use an object that doesn't physically exist. A simple way to bypass the problem is to add braces to introduce a new scope:

case 2:
{
	// 25 % chance of being able to run.
	int roll = Random(1, 4);

	if( roll == 1 )
	{
		cout << "You run away!" << endl;
		return true;//<--Return out of the function.
	}
	else
	{
		cout << "You could not escape!" << endl;
		break;
	}
}

This removes the ambiguity by forcing the scope of roll to be exactly within case 2.

Salem commented: *nods* +22
Narue 5,707 Bad Cop Team Colleague

>Why is it a bad practice to use it?
Laziness. Most of the time, people who use goto are too lazy to consider all of the alternatives and choose the best solution. They fall back on goto, but because they're lazy, they don't use it wisely and the result is the infamous "spaghetti code" you hear horror stories about.

It's also said to be a bad practice because of ignorance. This has nothing to do with the actual use of goto, but rather an incomplete understanding of the how, why, and when by those who make the most noise about goto being "evil".

However, with that said, if you have to ask why it's a bad practice, you're probably not yet qualified to use it wisely.

vmanes commented: Well put! +6
Narue 5,707 Bad Cop Team Colleague

Storage classes specify where an object is stored, its visibility (linkage) and how long it exists (storage duration).

There are three forms of linkage (summarizing):

  • external: The object is visible across the entire program.
  • internal: The object is visible only to a single file.
  • none: Basically a "super internal" linkage; the object is visible only to its scope where it doesn't explicitly have external or internal linkage.

There are also three types of storage duration:

  • automatic: The object exists until the end of its scope.
  • static: The object exists until the program terminates.
  • dynamic: The object exists until it is explicitly released.

Storage Classes

typedef: Technically it's not a storage class, but you use this when you want to define a synonym for an existing type:

typedef int foo; /* Now foo and int are interchangeable types */

extern: This specifies that an object has external linkage and static storage duration, meaning the object is visible across the entire program after compilation and linking and exists until the program terminates. The typical use of extern is "not defined here", meaning the object isn't defined in the current file, but a declaration is still required for successful compilation:

/* second.c */
extern int foo = 12345;
/* main.c */
/* Compiled with second.c */
#include <stdio.h>

int main ( void )
{
  extern int foo;

  printf ( "%d\n", foo );

  return 0;
}

You'll find extern declarations most often in …

Dave Sinkula commented: A good reference page. +17
Salem commented: Very nicely put. +23