User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,597 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,453 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 537 | Replies: 6
Reply
Join Date: Feb 2006
Location: Illinois
Posts: 14
Reputation: andrax is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
andrax andrax is offline Offline
Newbie Poster

dumb class scoping error

  #1  
Sep 6th, 2007
I know this is probably an unbelievably simple error somewhere, but I can't see it. I keep getting "undefined reference to Machine::Machine()" and all of Machine's other functions.

main.cpp
#include "machine.h"

using namespace std;

int main(int argc, char** argv) {
   Machine* m = new Machine();
   m->reset();
   m->run();
   delete m;
   return 0;
}

machine.h
#ifndef _MACHINE_H_
#define _MACHINE_H_

#include "user.h"

class Machine {
public:
   Machine();
   ~Machine();

   void run();
   void reset();

private:
   User currentUser;
};

#endif

machine.cpp
#include "machine.h"

Machine::Machine() {
}

Machine::~Machine() {
}

void Machine::run() {
}

void Machine::reset() {
}

I know I'm going to kick myself once someone answers this. Thanks in advance.
-andrax
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: dumb class scoping error

  #2  
Sep 6th, 2007
Is machine.cpp in your project / makefile?
Do you ever see machine.cpp being compiled when main.cpp is compiled?
Reply With Quote  
Join Date: Feb 2006
Location: Illinois
Posts: 14
Reputation: andrax is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
andrax andrax is offline Offline
Newbie Poster

Re: dumb class scoping error

  #3  
Sep 6th, 2007
Doesn't get to compile at all. The error keeps it from getting that far.

Makefile
OBJS = main.o machine.o user.o
EXENAME = sucrose
C = g++
COPTS = -g -Wall
LINK = g++
LINKOPTS = -o $(EXENAME)

$(EXENAME):  $(OBJS) $(LINK) $(LINKOPTS) $(OBJS)

main.o : main.cpp machine.h
        $(C) $(COPTS) main.cpp

machine.o : machine.cpp machine.h user.h
        $(C) $(COPTS) machine.cpp

user.o : user.cpp user.h
        $(C) $(COPTS) user.cpp

clean:
        -rm *o $(EXENAME)
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: dumb class scoping error

  #4  
Sep 7th, 2007
> $(EXENAME): $(OBJS) $(LINK) $(LINKOPTS) $(OBJS)
Shouldn't this be
$(EXENAME):  $(OBJS)
        $(LINK) $(LINKOPTS) $(OBJS)

Also, COPTS should also include the -c command line flag. This means "compile only", and is necessary to turn each file into its corresponding .o file. As written, each target tries to compile and link the whole program, which will cause the problem you see.

Does typing this at the command line also work?
g++ main.cpp machine.cpp user.cpp
Reply With Quote  
Join Date: Feb 2006
Location: Illinois
Posts: 14
Reputation: andrax is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
andrax andrax is offline Offline
Newbie Poster

Re: dumb class scoping error

  #5  
Oct 15th, 2007
I made those changes and it still doesn't work. The command-line statement gave the same error too.
Reply With Quote  
Join Date: Oct 2007
Posts: 13
Reputation: suntravel is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
suntravel suntravel is offline Offline
Newbie Poster

Re: dumb class scoping error

  #6  
Oct 15th, 2007
i have tested it too and give error
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: dumb class scoping error

  #7  
Oct 15th, 2007
Thanks for waiting a whole month to post "it doesn't work"

Now try again and post some actual command lines, actual error messages, and the code if it's different from what you originally posted.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 6:57 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC