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
chris_bacon
Feb 27, 2008
I'm working on a blackjack program for my c++ class, but I'm having trouble working with all the separate files. When I compile the driver program, I get:

code:
realgar% g++ driver.cpp
/tmp/ccVQ0FJW.o: In function `dealCards(Deck, SimplePlayer, Hand)':
driver.cpp:(.text+0xcc3): undefined reference to `SimplePlayer::expose(Card)'
driver.cpp:(.text+0xd39): undefined reference to `SimplePlayer::expose(Card)'
driver.cpp:(.text+0xd63): undefined reference to `SimplePlayer::expose(Card)'
collect2: ld returned 1 exit status
SimplePlayer is a class in I defined in a file called player.cpp, and I #included "player.cpp" so I'm not sure what the problem is here. Do I need to also define SimplePlayer in player.h ?

Adbot
ADBOT LOVES YOU

chris_bacon
Feb 27, 2008
Alright, one more related question. Whenever I try to compile deck.cpp, I get this error:

code:
rubric% g++ deck.cpp
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
I have no idea what could cause this. I didn't make an int main in deck.cpp, and I only included "deck.h" which also does not contain anything referring to 'main'. Any ideas?

chris_bacon
Feb 27, 2008

HB posted:

That error means that there is no main function anywhere that gcc can find. It's trying to produce an executable and can't figure out where your code takes over once the process is created.

Where is main? Is there a path of includes leading to it from deck.cpp? If you want to produce an object file for linking later you have to use a different invocation of gcc.

ah, I forgot to add -c when compiling. thanks for the help.

chris_bacon
Feb 27, 2008
Is it possible to use a struct or class in a templated function? I've already made a working, templated, double-linked list and now I'm trying to use it in a call center simulation.

I made the struct:

code:
struct caller_t {
  public: 
    string          status; 
    string          name;
    int           timestamp;
    int		  duration;
};
and I'm trying to insert a struct into my double-linked list, so I made a dynamic array of the caller_t struct.

When I compile, I get this:

code:
cse1695p58% g++ -Wall -Werror -o call call.cpp
call.cpp:38:32: error: character constant too long for its type
call.cpp:42:32: error: multi-character character constant
call.cpp:46:32: error: character constant too long for its type
call.cpp:50:32: error: multi-character character constant
call.cpp: In function ‘int main()’:
call.cpp:38: error: no match for ‘operator==’ in ‘(((caller_t*)(((long unsigned int)i) * 24ul)) + callers)->caller_t::status == 1768846701’
call.cpp:39: error: no matching function for call to ‘Dlist<caller_t>::insertFront(caller_t&)’
dlist.cpp:14: note: candidates are: void Dlist<T>::insertFront(T*) [with T = caller_t]
call.cpp:42: error: no match for ‘operator==’ in ‘(((caller_t*)(((long unsigned int)i) * 24ul)) + callers)->caller_t::status == 1735355492’
call.cpp:43: error: no matching function for call to ‘Dlist<caller_t>::insertFront(caller_t&)’
dlist.cpp:14: note: candidates are: void Dlist<T>::insertFront(T*) [with T = caller_t]
call.cpp:46: error: no match for ‘operator==’ in ‘(((caller_t*)(((long unsigned int)i) * 24ul)) + callers)->caller_t::status == 1819698546’
call.cpp:47: error: no matching function for call to ‘Dlist<caller_t>::insertFront(caller_t&)’
dlist.cpp:14: note: candidates are: void Dlist<T>::insertFront(T*) [with T = caller_t]
call.cpp:50: error: no match for ‘operator==’ in ‘(((caller_t*)(((long unsigned int)i) * 24ul)) + callers)->caller_t::status == 1852796517’
call.cpp:51: error: no matching function for call to ‘Dlist<caller_t>::insertFront(caller_t&)’
dlist.cpp:14: note: candidates are: void Dlist<T>::insertFront(T*) [with T = caller_t]
call.cpp:60: error: request for member ‘name’ in ‘curcaller’, which is of non-class type ‘caller_t*’
call.cpp:61: error: request for member ‘duration’ in ‘curcaller’, which is of non-class type ‘caller_t*’
Here's my insertFront for reference:

code:
template <class T>
void Dlist<T>::insertFront(T *o)
{
  node *np = new node;
  np->next = first;
  np->o = o;
  if (isEmpty()) {
    last = np;
  } 
  else {
    first->prev = np;
  }
  first = np;
}
Am I using incorrect syntax or is it not possible to do?

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