Thread: What's a link error?

  1. #16
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    I comped, linked, and ran all four of the second set of sources, and it sent "it's working!" to the screen. I did this on djgpp.

  2. #17
    Unregistered
    Guest
    Also, prelude, I find it quite helpful to include files needed for a class's implemenetation in that class's header. That way, if a class needs something that the rest of the program does not, I won't forget to include it. Also, including all fiels in the main sets up dependancies between them, so you can get subtle errors if you include things in the wrong sequence.

  3. #18
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I find it quite helpful to include files needed for a class's
    >implemenetation in that class's header.
    General rules of thumb aren't written in stone. I do the same thing as well when the situation warrants it.

    -Prelude
    My best code is written with the delete key.

  4. #19
    Registered User
    Join Date
    Mar 2002
    Posts
    15
    Ok I don't know what I did but I got it working now! Hopefully I can finish this program for monday. Thanks for all your help.

    Prelude, I think you might be right about the double underscore prefix. That's odd because in the assignment they didn't have that.

  5. #20
    Registered User
    Join Date
    Mar 2002
    Posts
    15
    Ok now I am trying to link the element files as well. The setAWeight function will be called from the aminoacid_analyzer but it is endefined identifier.

    aminoacid_main.cpp
    Code:
    #include "aminoacid_analyzer.h"
    
    int main( void )
    {
    	char elementFile[] = "elements.dat";
    	char acidFile[] = "aminoacids.dat";
    	
    	AminoAcidAnalyzer *aaa = new AminoAcidAnalyzer;
    	
    	aaa->populate(elementFile, acidFile);
    	
    	return 0;
    }
    aminoacid_analyzer.h
    Code:
    #ifndef AMINO_ACID_ANALYZER__
    #define AMINO_ACID_ANALYZER__
    
    #include <iostream.h>
    #include "element.h"
    
    class AminoAcidAnalyzer
    {
    	Element elements[5];
    	int acidCount;
    	
    	public:
    		AminoAcidAnalyzer();
    		void populate(char * elementFile, char * acidFile);		 
    		
    	private:
    		void populateElements(char * elementFile);
    		void populateAminoAcids(char * acidFile);
    };
    
    #endif
    aminoacid_analyzer.cpp
    Code:
    #include <iostream.h>
    #include "aminoacid_analyzer.h"
    //#include "element.h"
    
    AminoAcidAnalyzer::AminoAcidAnalyzer()
    {
    	acidCount = 0;
    }
    
    void AminoAcidAnalyzer::populate(char *elementFile, char *acidFile)
    {
    	populateElements(elementFile);
    	populateAminoAcids(acidFile);
    }
    
    void AminoAcidAnalyzer::populateElements(char * elementFile)
    {
    	setAWeight(); <--- undefined identifier
    }
    
    void AminoAcidAnalyzer::populateAminoAcids(char * acidFile)
    {
    	cout<<"populateAminoAcids";
    }
    element.h
    Code:
    #ifndef ELEMENT__
    #define ELEMENT__
    
    class Element
    {
    	char atomic_symbol;
    	double atomic_mass;
    	
    	public:
    		void setAWeight();
    		void getAWeight(char * elementFile);
    };
    
    #endif
    element.cpp
    Code:
    #include "element.h"
    
    void Element::setAWeight()
    {
    
    }
    
    void Element::getAWeight(char * elementFile)
    {
    }

  6. #21
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    This is getting to be an interesting project.

    The problem now is that Element::setAWeight() is called from outside the class Element without qualification. You will need to call the setAWeight() member of one of your class' Element element[]'s. Remember, class AminoAcid has data members of type Element, but Element is not a nested class declaration, so only the instantiations of Element are in scope, not the member functions of Element.

    So if you want to setAWeight for one of your elements, you will need to make a pub function in AminoAcid that takes an int, and have it call a member of one of it's Element objects, like this:

    Code:
    AminoAcid::Weight(int e, whatever) {
    element[e]->setAWeight(whatever);
    }
    If Element is to be an implementation detail of AminoAcid, then any required functons in Element need to be made available via AminoAcid.

    Hehe, you have too many more problems and I'm gonna need to retake chem 1101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  5. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM