Here's a way you could implement C#'s property concept:
We want the public member variable INITIALIZED to be read-only. Here's how to implement it.
class A
{
public:
A() : INITIALIZED(initialized_)
{
initialized_ = 100;
}
void reconf(int i)
{...
I found a declaration like this:
void h(int());
What does this mean? Is that argument a pointer to function or what? If it was intended as a pointer to function then should it be declared like this:
void h(int (*)());
Rome did not create a great empire by having meetings, they did it...
Hello all!
I am experimenting with pthreads. Now I have encountered an unexpected behavior (at least I think it is). The code is show below:
#include <iostream>
#include <pthread.h>
using namespace std;
void* task(void* arg)
{
cout << "Starting task" << endl;
for(int count =...
Hi all!
The STL multimap accepts duplicate keys such that the following entry is valid for a multimap:
KEY VALUE
foo bar
jack jill
Now the problem is, multimap also accepts duplicate entries such that if I would add another foo, bar pair the multimap will accept it. So...
I have read in most articles that STL is not thread-safe or should not be used in multi-threading? Why? What are other alternatives or how should one make a thread-safe STL?
Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.
- janvier -
Hi guys! What is the corrext way to handle exceptions during construction of a member object?
A code snippet is give below:
class SomeException {};
class A
{
public:
A() throw(SomeException)
{
if(...)
{
throw SomeException();
}...
Hi!
I am having a bit of a problem getting the local address of my computer. For example, my IP is something like 192.68.1.100. When a do a ifconfig -a, I can see that eth0 is assigned the said IP. So naturally, I tried getting the IP using the socket APIs. However, no matter how hard I try, I...
I have code that returns a reference to a member variable. The member variable is a vector of a certin class. This class consumes 5848 or more bytes.
The process is like this, I loop on the number of objects in the vector described above using iterators in a for() loop. So I have a class like...
Assuming I have a vector and an iterator for it. Assuming also that the vector contains elements. Also assume a function fxn() exists.
...
struct A;
void fxn(A& theA);
...
vector<A> vectorA;
vector<A>::iterator iterA;
...
...
for(iterA = vectorA.begin(); iterA != vectorA.end(); ++iterA)
{...
Hi all! I got a problem regarding POSIX threads specifically pthread_mutex_lock and pthread_mutex_unlock.
Here is the code:
#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace std;
void* doRunA(void* arg);
class A
{
public:
A() : a(0) { }
void Run()
{...
I need help!
Why won't this work?
deque<ContactInfo>::iterator contact_info_iter;
for(contact_info_iter = contact_list.begin(); contact_info_iter != contact_list.end(); contact_info_iter++)
{
contact_list.erase(contact_info_iter);
}
Rome did not create a great empire by having meetings...
What is an __attribute__?
What is this good for?
What things similar to __attribute__ should I know in gcc?
Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.
- janvier -
Using the system calls related to sigaction() and signal set manipulation, i.e. sigaddset(), sigfillset(), etc., how would I implement a signal handler to block only SIGUSR1 and SIGUSR2 and ignore other signals?
I tried this without using sigprocmask() by first creating a signal set to be...
Can someone tell me the effects of the static object on the statements that are numbered?
SomeCode.cpp
#include "../RSS/RSSInfo.h"
using RSS::RSSInfo ;
static RSSInfo fxnOne(void) ; // ??? (1)
static RSSInfo& fxnTwo(void) ; // ??? (2)
static RSSInfo rss_1 ; // ??? (3)
int main()
{...
Will it be possible to call a contructor from another constructor in a single class?
Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.
- janvier -
Why won't this work?
class Base
{
public:
Base()
{
}
Base(const char* msg)
{
}
} ;
class Sub : pulic Base
{
Sub()
{
}
Sub(const char* msg)
{
Base::Base(msg) ;
}
} ;
Why isn't the above code the same as this one (that works):
class Base
{...
What would happen if the overloaded assignment operator returns an object by value rather than by reference?
Meaning, the 'operator=' is implemented like below:
// Assume there is class named 'B' with a single member
// variable named 'int i'
B B::operator=( const B& b )
{
B my_b ...
Suppose I have two functions, one returns a reference to an object and the other returns an object by value. See below:
// Assume 'B' is a well-defined class
B& fn(B& b) // returns an object reference
{
b.i++ ;
return b ;
}
B fn2(B& b) // returns an object by value
{
b.i++...
What are lvalues and rvalues as stated in the C++ standard? Also, what is cv-qualified as stated in the C++ standard?
I just know that lvalues can be found on the left side of an operator and rvalues on the right. Also they say lvalues are objects.
What else does lvalue and rvalue mean? Same...
I am reading about C++ references. I came about the code that cannot compile. Here is the code:
int& i = 1 ; // this will cause a compiler error
const int& j = 1 ; // this works
On my compiler, it says Initialization of non-const reference type 'int&' from rvalue of type 'int'. Can...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.