You make a very good point.
\me quickly scurries off to modify some code
User Profile
Collapse
-
If you want to do this in a portable way you need to use relative locations:
Code:#include "../dir_name/file.h"
Leave a comment:
-
It all depends what you intend to do with this list, but if you just want to access the data without modifying it then the best thing might be:
[code=cpp]const vector<int>& get_vector_list ( void ) const
{ return vectorlist; }[/code]
That will prevent it from being modified. Alternatively you might want to provide access only to the "at" function and const_iterator "begin" and "end" fu...Leave a comment:
-
The default behaviour is to copy! Deep and shallow are just programming concepts. The notion of shallow copying comes from the fact that if you copy a pointer you are copying a memory address; as such your copied object contains a pointer that points at the same place as your original object's pointer.
In essence "shallow copy" means to copy a pointer directly rather than constructing a copied pointer via new....Leave a comment:
-
Shallow copy usually means copying a pointer, rather than the underlying data; this means changes to the copied object will be reflected in the original. You can probably supply your own "source code" now....Leave a comment:
-
How hard is it to type "primality test"? Not very I've done it for you... http://en.wikipedia.org/wiki/Primality_test...Leave a comment:
-
This is how you do "double to long" floor, ceil, round and truncate in C++:
[CODE=cpp]
#include <cmath>
namespace math
{
inline void floor( const double& value, long& floored ){
floored = static_cast<lon g>( ::floor( value ) );
}
inline void ceil( const double& value, long& ceiling ){
ceiling = static_cast<lon g>( ::ceil(...Leave a comment:
-
I seem to remember VS2005 having some application called spy++ (or something with the name spy in) which gives you memory handles of controls in a program. That might help you get access to the functionality you need. However the one time I tried to use it it seemed like a total swine (not spy++ using the handles)....Leave a comment:
-
Have you triedCode:./t1
Leave a comment:
-
What you need is a little boost magic.
http://cci.lbl.gov/~rwgk/shortcuts/b...s_base_of.html
http://www.boost.org/libs/mpl/doc/refmanual/if.html
What you can do in this case is get the "if" object to return an empty function object if the input isn't derived from your base, and it will return the function object that does whatever it is you...Leave a comment:
-
I think that you might even have gcc (the compiler) already installed on your mac. Try typing gcc on the command line. Then all you need is a text editor and you are ready to go....Leave a comment:
-
When you say 'we,' one would naturally assume that you meant 'one' (unless you are the Queen of England, Your Majesty) ;)...Leave a comment:
-
That is not necessarily true. It is a member function of Set and it would work perfectly well if Set::operator[](std::size_t) were overloaded (which is what the compiler is saying), and Set contained an array called set....Leave a comment:
-
You've got the right idea, but your code doesn't even come close to compiling. Start simple and go from there. A good approach is to get one aspect of your code working and then move on to the next thing, don't do it all at once. This should get you started:
[CODE=cpp]#include <iostream>
// general function declarations
// class declaration
class matrix
{
private :
int rows;...Leave a comment:
-
[CODE=cpp]
//March 19, 2008
//Exercise 5.23 and 5.24
//Project 1
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
int main()
{
cout<<"Project 1"<<endl;
cout<<"name"<<e ndl;
cout<<"March 19, 2008"<<endl;
cout<<"Computer Science...Leave a comment:
-
You can do this very efficiently with a function object:
[CODE=cpp]
class sum_fac {
const long& operator( )( void ) {
// compute the new factorial
// Increase the partial sum
return sum_;
}
private:
long _i;
long _fac;
long _sum;
};
[/CODE] See if you can add in the details....Leave a comment:
-
what you want to do to begin with is probably add some typedefs, this makes things nicer.
Code:class irrigation_estimator { public: typedef irrigation_estimator type; typedef irrigation_component component_type; typedef std::vector<component_type> component_vector_type; private: component_vector_type componentVector_; std::string companyName_; std::string businessName_;
Leave a comment:
-
Oh while I am on really useful things ... With vectors NEVER[CODE=cpp]for( int i = 0; i != my_vector.size( ); ++i ) { ... }[/CODE]and ALWAYS[CODE=cpp]for( std::vector<my_ type>::iterator it = my_vector.begin ( ); it != my_vector.end( ); ++it ) { ... }[/CODE]You need a REALLY good reason to break that rule ;) So your code becomes[CODE=cpp]
for ( std::vector<std ::string>::iter ator it = str_Vector.begi n( ); it != str_Vector.end( );...Leave a comment:
-
No problem. Stringstreams are one of the most useful objects in the std library :) It took me a while to work that one out myself. Glad to be of assistance.Leave a comment:
-
You could try using a stringstream or an iostream, they both inherit from istream and ostream, as such you can push things into them and then get them out afterwards. It will also work in your function[CODE=cpp]#include <sstream>
int main (void) {
std::stringstre am ss;
"for each" (vector) {
ss << element;
}
F1(ss);
}[/CODE]That is pseudo...Leave a comment:
No activity results to display
Show More
Leave a comment: