Forum: C++ Aug 12th, 2008 |
| Replies: 3 Views: 1,020 When you build and run a project in Xcode, the executable is placed in the build/Debug (or build/Release) folder relative to the project directory. |
Forum: C++ Jul 22nd, 2008 |
| Replies: 8 Views: 559 Perhaps your compiler decided to optimize the code by substituting the contents of the function for the function call as if the function were declared inline. |
Forum: C++ Jul 22nd, 2008 |
| Replies: 16 Views: 4,434 If you are assigning the return value of the new operator to arrays, it had better be a pointer.
Space in memory is reserved whether you use dynamic allocation or not. What that space holds is... |
Forum: C++ Jul 22nd, 2008 |
| Replies: 16 Views: 4,434 Just because it works with your compiler does not mean it will work with others. The initial values of an array are undefined in C++, which means they may be 0 or anything else.
To initialize an... |
Forum: C++ Jul 21st, 2008 |
| Replies: 16 Views: 4,434 As this is C++, you can use STL functions to do the work for you:
#include <algorithm>
#include <iostream>
int main()
{
int array[] = { 2, 5, 8, 1, 4, 2 };
size_t array_size = 6;
... |
Forum: C++ Jul 15th, 2008 |
| Replies: 13 Views: 1,292 Reverse psychology works well, it would seem. :P |
Forum: C++ Jul 15th, 2008 |
| Replies: 13 Views: 1,292 I learned Java as my first programming language by reading Beginning Java by Ivor Horton. The book weights in at over 1000 pages. I found that an encyclopedic tutorial is an excellent way to learn... |
Forum: C++ Jul 13th, 2008 |
| Replies: 3 Views: 392 Read the comments in the input function. |
Forum: C++ Jul 11th, 2008 |
| Replies: 2 Views: 422 There is no operator for raising to powers in C++ similar to the ** operator in Python. You can do the multiplication or use the pow library function as suggested. |
Forum: C++ Jul 10th, 2008 |
| Replies: 4 Views: 1,368 Is there a difference, in terms of performance, between the two loops below? (myvec is type std::vector<int>.)
std::vector<int>::const_iterator pos;
for (int i = 0; i < N; i++) {
pos =... |
Forum: C++ Jul 8th, 2008 |
| Replies: 3 Views: 976 You can use the std::noskipws stream manipulator to alter the behavior of the stream. See here (http://www.cplusplus.com/reference/iostream/manipulators/noskipws.html). |
Forum: C++ Jul 8th, 2008 |
| Replies: 7 Views: 945 That is a neat trick. Thanks. |
Forum: C++ Jul 7th, 2008 |
| Replies: 4 Views: 922 I figured it out. I was calling the std::vector constructor with the arguments reversed (as well as providing an incorrect initial size). The solution:
Polynomial(int val = 0, int exp = 0) :... |
Forum: C++ Jul 7th, 2008 |
| Replies: 4 Views: 922 coefs is initialized in the initializer list of the constructor:
Polynomial(int val = 0, int exp = 0) : coefs(0, exp), degree(exp)
Am I missing something? Thanks. |
Forum: C++ Jul 7th, 2008 |
| Replies: 4 Views: 922 The default copy constructor should work for the Polynomial class below because it does not contain any dynamic data types. However, when I create a new Polynomial via the copy constructor, it... |
Forum: C++ Jul 7th, 2008 |
| Replies: 7 Views: 945 I did some searching on this topic but couldn't find anything definitive.
Are basic types automatically initialized to 0 in C++ when allocated via new? For example, are all values of nums... |
Forum: C++ Jul 7th, 2008 |
| Replies: 48 Views: 3,274 You are calling payroll::setvariables twice with 4 arguments, whereas the function definition specifies that it requires 7 arguments. In addition, you have not defined the function, only declared it. |
Forum: C++ Jul 7th, 2008 |
| Replies: 11 Views: 1,618 |
Forum: C Jul 7th, 2008 |
| Replies: 7 Views: 1,980 How about this:
char *ns = malloc(l * sizeof(*ns)); |
Forum: C++ Jul 7th, 2008 |
| Replies: 2 Views: 683 Alternatively you can use STL functions:
#include <string>
#include <algorithm>
...
std::string::iterator end_pos = std::remove(str.begin(), str.end(), '\\');
str.erase(end_pos, str.end()); |
Forum: C++ Jul 6th, 2008 |
| Replies: 13 Views: 1,394 Ignore the pass-by-value/pass-by-reference discrepancies in the function declarations in my previous post. |
Forum: C++ Jul 6th, 2008 |
| Replies: 13 Views: 1,394 gcc 4.0.1
@vijayan121: Thanks for the info, I have updated my code.
----------
As a matter of style, is it better (in general) to write:
template <typename T1,
typename T2,
... |
Forum: C++ Jul 5th, 2008 |
| Replies: 13 Views: 1,394 sarehu's code works for me. |
Forum: C++ Jul 5th, 2008 |
| Replies: 13 Views: 1,394 Thanks, that is just what I was looking for.
What does this mean: template <typename> class Container? I can figure out what it does, but typename is not followed by a name, which I find... |
Forum: C++ Jul 4th, 2008 |
| Replies: 13 Views: 1,394 I have a template function as follows:
template <typename T>
int my_func(T& arg)
T is expected to be of type map<T1, T2>. T1 is expected to be of a basic type (int, long, etc.) and T2 is... |
Forum: C++ Jul 4th, 2008 |
| Replies: 2 Views: 488 If I declare a struct node, is the following legal in C++?
node nodes_array[vector.size()];
I know this is not legal in C. However, my C++ compiler does not complain. Is this only in recent... |
Forum: C++ Jul 4th, 2008 |
| Replies: 18 Views: 2,658 Like ruggedrat said, a breadth first search will suffice. Starting at M, mark each reachable node as distance 1; from those nodes, mark each reachable node that has not already been visited as... |
Forum: C++ Jul 4th, 2008 |
| Replies: 9 Views: 846 Ah, I'm an idiot. Some of the entries in Board::pieces were NULL. Thanks for pointing that out. |
Forum: C++ Jul 4th, 2008 |
| Replies: 9 Views: 846 Thanks for the info.
The move function is empty: void Pawn::move(int rank, int file) { }. I should mention that Pawn (the type that is returned by board[0][0]) is a subclass of the pure... |
Forum: C++ Jul 3rd, 2008 |
| Replies: 9 Views: 846 Although my last question has not yet been answered, I have another. What is the difference between Piece* const* and Piece** const? |
Forum: C++ Jul 3rd, 2008 |
| Replies: 9 Views: 846 Here is my code for Board.h:
#ifndef BOARD_H
#define BOARD_H
#include <iostream>
#include "Piece.h"
static const int BOARD_DIM = 8; |
Forum: C++ Jul 3rd, 2008 |
| Replies: 9 Views: 846 @vijayan121: That would work, but I want to be able to modify the Piece corresponding to board[0][0].
Board b;
const Piece *p = b[0][0];
p.move(0,0); // not legal
Does this mean that I... |
Forum: C++ Jul 3rd, 2008 |
| Replies: 9 Views: 846 I am writing a chess game to familiarize myself with the C++ language. I have a Board class which contains a 2D array of pointers to Piece objects. I want to implement Board::operator[] such that... |
Forum: Java Mar 28th, 2007 |
| Replies: 3 Views: 2,373 An even better way to do this would be to create a Person class with the appropriate fields, and create a new class that implements Comparator for each desired sort order. See here... |
Forum: Java Mar 28th, 2007 |
| Replies: 10 Views: 2,750 float fah = console.nextFloat(); |
Forum: Java Mar 23rd, 2007 |
| Replies: 7 Views: 11,759 You can use a javax.swing.JFormattedTextField with a java.text.NumberFormat as the format. For example:
numberField = new JFormattedTextField(NumberFormat.getInstance()); |