|
|
Up |
|
|
  |
|
|
  |
Author: Joost KraaijeveldJoost Kraaijeveld
Date: Feb 11, 2008 21:26
Hi,
Are Base data members accessible in Derived constructor initialiser list
and is the following legal?
class Base
{
public:
protected:
std::string text;
};
class Derived : public Base
{
public:
Derived(const std::string& aText)
: text(aText)
{}
};
TIA
Joost
|
| |
|
| |
6 Comments |
|
  |
Author: icemaniceman
Date: Feb 11, 2008 21:07
Hi All,
Suppose that my program is such that
int counter;
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
void *functionC()
{
pthread_mutex_lock( &mutex1 );
counter++;
printf("Counter value: %%d\n",counter);
pthread_mutex_unlock( &mutex1 );
}
int main()
{
pthread_t thread_id;
pthread_create (&thread_id, NULL, &functionC, NULL);
//increment counter in main also
}
|
| Show full article (0.63Kb) |
|
4 Comments |
|
  |
Author: GregGreg
Date: Feb 11, 2008 19:05
Lately I have been Customizing C commands into another language
(Shona) to facilitate easier learning of C by Shona speaking people
using pre-processor directives i.e. (#include define)
is there a better way to have C or C++ available in another language.
|
| |
|
5 Comments |
|
  |
Author: icemaniceman
Date: Feb 11, 2008 18:42
Hi,
I need to implement a timer associated with a state[in a state
machine].In case the statemachine does not get any input for a
particular period of time, the timer should reset and there should be
default action.
How do I implement multiple threads in c++[in linux].
I got this example on the web .its uses 2 threads.but it does not
execute together.
thread 1 executes then thread 2
void *task1(void *X);
void *task2(void *X);
int main(int argc, char *argv[])
{
pthread_t ThreadA,ThreadB;
int N;
if(argc != 2){
std::cout << "error" <<"\n";
exit (1);
}
|
| Show full article (1.39Kb) |
|
8 Comments |
|
  |
Author: JSebJSeb
Date: Feb 11, 2008 17:10
Hi there gurus,
This is a design question. Hope I'll get some insights!
Trying to get back in shape with C++, I'm writing a nice BST class. So
I have a nice class TreeNode:
template class TreeNode
{
private:
T* mpData;
const TreeNode* mpLeftChild;
const TreeNode* mpRightChild;
TreeNode(const T& aData)
: mpData(&aData), mpLeftChild(NULL), mpRightChild(NULL)
{ }
// ...
};
Type T can be a huuuuuge class, so when I initialize a node with data
of this type, I make mpData point directly to the original data. That
is, I don't call type T's copy constructor.
|
| Show full article (1.47Kb) |
|
4 Comments |
|
  |
Author: JackCJackC
Date: Feb 11, 2008 11:17
Hi,
Im having some problems working out how I can read the last 5 bytes of
a file which i already have open. Heres what i have tried:
pFile = fopen ("/home/jc/data.txt" , "rw");
// Some IO here (preserve position pointer required)
// Read in last 5 bytes
fseek(pFile, 5, SEEK_SET);
fgets(buffer, 5, pFile);
// More IO here (resume old position pointer)
fclose(pFile);
This doesn't work because SEEK_SET adds 5 onto the end of the file, i
need a way to set the position to the current end - 5 bytes, whilst
preserving the current position once im done.
Any ideas on how to approach this? I thought about getting the file
size and using fseek with SEEK_SET from the beginning of the file, but
i think this would involve closing/reopening the file which i would
like to avoid.
Thanks alot for any help,
Jack
|
| |
|
3 Comments |
|
  |
Author: DanielJohnsonDanielJohnson
Date: Feb 11, 2008 10:12
I have a little confusion with this kind of situation.
Suppose there are two functions, Function First allocates a memory and
then call Function Second..... But in Function Second Exception
occurs!!! How can we notify Function First about this in order to
deallocate the memory allocated by First ?
I found something from Stroutup's web page, saying that it can't be
done ?
http://www.research.att.com/~bs/bs_faq2.html#resume
I was thinking that if we can catch this exception in the second
function then either 1) rethrow so that the first function can catch
it then deallocate appropriately 2) Catch and return an error value
OR
The second is that a function doesn't have to catch it at all. The
exception would automatically be rethrow to the first function.
Can C++ gurus throw some insight into such situations ?
|
| |
|
3 Comments |
|
  |
|
|
  |
|
|
  |
|
|
|
|
|
|
|