I would like to ask you how to write a copy constructor (and operator = ) for the following classes.
Class Node stores coordinates x,y of each node and pointer to another node.
class Node
{
private:
double x, y;
Node *n;
public:
Node (double xx, double yy, Node *nn) : x(xx), y(yy), n(nn) {}
void setNode (Node *nn) : n(nn) {}
...
};
...
Hello there, This is related to my previous question. Basically, given a string of characters, how do I go through it and assign all the numbers within that string into an integer variable leaving out all other characters?
Not at input but when there is a string of characters already read in through gets();
...
Hi All,
I was just going thro' source code of Yahoo's Trafic Server
It is written in C++.
In almost all methods (from one of modules),
they do void(param) on each param that function receive.
(Eg below)
Can someone explain what this could be for ?
int ...
I have recently found out that there exists a method called nth_element in the STL. To quote the description:
Nth_element is similar to
partial_sort, in that it partially
orders a range of elements: it
arranges the range [first, last) such
that the element pointed to by the
iterator nth is the same as the
element that wou...
The following code works with Visual Studio 2008 but not with GCC/G++ 4.3.4 20090804. Which behaviour is - according to the C++ standard - correct?
template <int N>
struct A : A<N-1> {};
template <>
struct A<0> {};
struct B : A<1> {};
template <int N>
void Func(const A<N> &a) {}
int main()
{
A<1> a; //is derived from A<0>
...
In preparing to a OOP exam, I enjoyed seeing g++ compile the following code (without an instantiation) even though it appeared to make no sense:
template<class T> void f() {
T t = "a";
t += 5.6;
t->b();
T* p = t;
p = p*(t/"string");
}
I then set out on a challenge to make this instantiate and compile.
I created th...
Consider following code:
#include <iostream>
using namespace std;
int main()
{
int x, y, i;
cin >> x >> y >> i;
switch(i) {
case 1:
// int r = x + y; -- OK
int r = 1; // Failed to Compile
cout << r;
break;
case 2:
r = x - y;
cout << r;
...
I want to get the number of seconds since midnight.
Here is my first guess:
time_t current;
time(¤t);
struct tm dateDetails;
ACE_OS::localtime_r(¤t, &dateDetails);
// Get the current session start time
const time_t yearToTime = dateDetails.tm_year - 70; // year to 1900 converted into year to 1970
const t...
Is it possible to find the second maximum number from an array of integers by traversing the array only once?
As an example, I have a array of five integers from which I want to find second maximum number. Here is an attempt I gave in the interview:
#define MIN -1
int main()
{
int max=MIN,second_max=MIN;
int arr[6]={0,1,2,3,4,...
struct Group
{
Group(string _N, set <string> M_)
{Name = N_; Member = M_}
string Name;
set <string> Members;
};
int main()
{
list <Group> GroupList;
set <string> Members;
//collect the members from a file and add to set
GroupList.pushback(Group(Name, Members));
}
is there a less memory consuming way to the a...
I have a set like this:
set<vector<prmNode> > cammini
I need to take 2 random values (2 random vector) from this set. How could I do??
Thank you very much!
...
Hi, i'm pretty new at using C++ and I'm actually stopped at a problem.
I have some class A,B,C defined as follow (PSEUDOCODE)
class A
{
...
DoSomething(B par1);
DoSomething(C par1);
...
}
class B
{
A parent;
...
}
class C
{
A parent;
...
}
The problem is :
How to make this? If I simply do it (as I've always done in c...
I am working on a transliteration tool. I have two modules lexer and translator. Lexer generates tokens out of the input text. Depending on the current language chosen, I have to call appropriate translation routine.
I have came up with couple of ideas to do this. First one is to create a base class something called base_translator and ...
Related to my other question, I have now modified the sparse matrix solver to use the SOR (Successive Over-Relaxation) method. The code is now as follows:
void SORSolver::step() {
float const omega = 1.0f;
float const
*b = &d_b(1, 1),
*w = &d_w(1, 1), *e = &d_e(1, 1), *s = &d_s(1, 1), *n = &d_n(1, 1),
*xw...
Possible Duplicate:
How do I set the icon for my application in visual studio 2008?
I use Microsoft Visual C++ 2008 express edition, And I wonder how I can use my .ico file for the exe instead of the default washing machine looking one?
...
Hi there,
I need to compare the performance of AS3, Processing and openFrameworks for my Bachelor thesis. Are there any comparison tables you know of or do I have to do the test myself?
How would a good test look like? I'm just focused on graphics so I thought about maybe three different programs, a 2d-graphics app, a typographic-app ...
From previous post, I learnt that for there are two ways, at least, to declare an array without default constructors. Like this
class Foo{
public:
Foo(int i) {}
};
Foo f[5] = {1,2,3,4,5};
Foo f[5] = {Foo(1), Foo(2), Foo(3), Foo(4), Foo(5)};
I also learnt that the first one will construct the object using the parameter...
When I run gcc with the parameter -fdump-rtl-jump, I get a dump file with the name file.c.135r.jump, where I can read some information about the intermediate representation of the methods in my C or C++ file.
I just recently discovered, that the static methods of a project are missing in this dump file. Do you know, why they are missing...
I tried http://code.google.com/p/feed-reader-lib but holy cow, talk about difficult to build. It has a nightmare of dependencies on Xerces and Xalan, both of which seem to be choking under the new VisualStudio 2010 C++ compiler. I've wasted hours trying to build this thing which is a shame. Does anyone have anything a little easier to hi...
One question about protected constructor. I learnt that the protected constructor can be used in the derived class. How ever, I found the code below has an error. Why does it happen like this?
class A
{
protected:
A(){}
};
class B: public A {
public:
B() {
A* f=new A(); // Why it is not wor...