CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Oct 2010
    Posts
    106

    undefined reference to Struct

    Code:
    breachmonitor.cpp:(.text+0x17ce): undefined reference to `BreachMonitor::Breach::Breach()'
    Can anyone please tell me what does it mean? I have created a struct and then declared its variable like

    Code:
    Breach wb;
    and it isnt compiling. The structure has default constructor (no arguments) and another one for initialization. It has also got two methods.

    Code:
    bool operator==(const Breach& p) const
    bool operator<(const Breach& p) const

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: undefined reference to Struct

    Could you post a complete snippet including BreachMonitor
    Victor Nijegorodov

  3. #3
    Join Date
    Oct 2010
    Posts
    106

    Re: undefined reference to Struct

    Actually it is my office work and I am afraid I wont be able to send the class but do you have any idea of what the problem could be.

    Code:
    struct Breach
    	{
    		  string trdr;        /*!< Trader itm */
    		  string sendt;       /*!< Time of message transmission */  
    		  string com;         /*!< Commodity */
    		  
    		Breach();
    
    		Breach(const std::string& _trdr, const std::string& _sendt, const std::string& _com): trdr(_trdr), sendt(_sendt), com(_com) {}
    	
    		bool operator==(const Breach& p) const
    		{
    			return trdr == p.trdr && com == p.com;
    		}
    
    		bool operator<(const Breach& p) const
    		{
    			if(trdr < p.trdr) return true;
    			if(trdr > p.trdr) return false;
    			if(com < p.com) return true;
    			if(com > p.com) return false;	
    
    			return false;
    		}
    	};

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: undefined reference to Struct

    The default constructor for the Breach type is either not implemented, or is in a file which is not being compiled alongside the main file.

  5. #5
    Join Date
    Oct 2010
    Posts
    106

    Re: undefined reference to Struct

    How do I implement the default construct? It is inside the main() file.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: undefined reference to Struct

    Code:
    Breach() {;}
    Victor Nijegorodov

  7. #7
    Join Date
    Oct 2010
    Posts
    106

    Re: undefined reference to Struct

    THANK YOUUUUU VICTOR . It worked .

  8. #8
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: undefined reference to Struct

    Well, the ; is unnecessary there.

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: undefined reference to Struct

    Quote Originally Posted by Lindley View Post
    Well, the ; is unnecessary there.
    Yes! I just forgot to delete it while updatiing the original code...
    Victor Nijegorodov

  10. #10
    Join Date
    Oct 2010
    Posts
    106

    Re: undefined reference to Struct

    Thanksss

  11. #11
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: undefined reference to Struct

    Why do you use shorthand variable names that then have to be commented as to their purpose?

    Code should be self-documenting as much as possible and so variables named properly go a long way towards that goal.
    Get Microsoft Visual C++ Express here or CodeBlocks here.
    Get STLFilt here to radically improve error messages when using the STL.
    Get these two can't live without C++ libraries, BOOST here and Loki here.
    Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
    Always use [code] code tags [/code] to make code legible and preserve indentation.
    Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

  12. #12
    Join Date
    Oct 2010
    Posts
    106

    Re: undefined reference to Struct

    You are right. I am making changes to an already existing code. But will follow you advice while making those changes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured