Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
FatCow
Apr 22, 2002
I MAP THE FUCK OUT OF PEOPLE
I'm using a stl set to hold multiple instances of a class. Is it considered poor form to make things 'mutable' that aren't used in the comparison operator to get around the implicit cast to const?

Adbot
ADBOT LOVES YOU

FatCow
Apr 22, 2002
I MAP THE FUCK OUT OF PEOPLE

Drx Capio posted:

...But yeah, it's kind of bad form because mutable usually designates pretty specific functionality like access statistics and caching. The general rule is that the (visible) state of the object should never change in a const method.

That Turkey Story posted:

It's kind of hackish, have you considered using a map instead or are you unable to partition the type? If you have Boost you might also want to consider using a Multi-Index Container and modify the value with its "modify" function template.

Thanks. I switched to a map and pulled the items used in the index since they aren't needed other then for searching on.

FatCow fucked around with this message at 23:44 on Mar 13, 2008

FatCow
Apr 22, 2002
I MAP THE FUCK OUT OF PEOPLE
This one had me stumped for a hour or so at work before I got pulled away. When I compile my application everything works fine. When it tries to link I get " undefined reference" to everything in the threadqueue class (Quick wrapper around STL queues to make it threadsafe).

There has to be something so obviously stupid here but I can't see it.

threadqueue.h
code:
#ifndef _THREADQUEUE_H_
#define _THREADQUEUE_H_

#include <pthread.h>

#include <queue>
using namespace std;

template <class T>
class threadqueue {

        private:
                pthread_mutex_t mutex;
                queue<T> data;
        public:
                threadqueue();
                ~threadqueue ();

                void push ( const T& );
                T pop ();
                int size ();
};
#endif
threadqueue.cpp
code:
#include <pthread.h>

#include <queue>
using namespace std;

#include "threadqueue.h"

template <class T> threadqueue<T>::threadqueue () {
        pthread_mutex_init (&mutex, NULL);
}

template <class T> void threadqueue<T>::push( const T& x ) {
        pthread_mutex_lock(&mutex);
        data.push(x);
        pthread_mutex_unlock(&mutex);
}

template <class T> T threadqueue<T>::pop( ) {
        pthread_mutex_lock(&mutex);
        T x;
        x = data.front();
        data.pop();
        pthread_mutex_unlock(&mutex);
        return x;
}

template <class T> int threadqueue<T>::size () {
        return data.size();
}
GCC output
code:
g++ -o threadqueue.o -c -g -O0 -Wall -Ulinux -Dlinux=linux -I/usr/local/ssl/include -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -I/usr/lib/perl5/5.8.8/i686-linux/CORE threadqueue.cpp
g++ -o acdtool -Wall  threadqueue.o main.o acdtool.o listener.o dialog.o collector.o snmp.o util.o dispatch.o ldr_pcap.o ./libs/libosip2.a ./libs/libosipparser2.a -lpcap -lpthread `net-snmp-config --agent-libs`
acdtool.o: In function `acdtool::main_loop()':
/home/me/acdtool.cpp:86: undefined reference to `threadqueue<acd_message*>::size()'
/home/me/acdtool.cpp:91: undefined reference to `threadqueue<acd_message*>::pop()'
acdtool.o: In function `acdtool::addMessage(acd_message*)':
/home/me/acdtool.cpp:73: undefined reference to `threadqueue<acd_message*>::push(acd_message* const&)'
acdtool.o: In function `~acdtool':
/home/me/acdtool.cpp:68: undefined reference to `threadqueue<acd_message*>::~threadqueue()'
/home/me/acdtool.cpp:68: undefined reference to `threadqueue<acd_message*>::~threadqueue()'
/home/me/acdtool.cpp:68: undefined reference to `threadqueue<acd_message*>::~threadqueue()'
/home/me/acdtool.cpp:68: undefined reference to `threadqueue<acd_message*>::~threadqueue()'
acdtool.o: In function `acdtool':
/home/me/acdtool.cpp:21: undefined reference to `threadqueue<acd_message*>::threadqueue()'
/home/me/acdtool.cpp:36: undefined reference to `threadqueue<acd_message*>::~threadqueue()'
/home/me/acdtool.cpp:21: undefined reference to `threadqueue<acd_message*>::threadqueue()'
/home/me/acdtool.cpp:36: undefined reference to `threadqueue<acd_message*>::~threadqueue()'
collect2: ld returned 1 exit status
make: *** [all] Error 1
$ nm threadqueue.o
$

$ strip threadqueue.o
$ -rw-rw-r-- 1 me me 432 Dec 9 04:26 threadqueue.o

FatCow
Apr 22, 2002
I MAP THE FUCK OUT OF PEOPLE
That did it, what a stupid mistake.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply