Hi, everyone!

I'm having trouble with a linker error (I'm using Visual Studio 2008) and I would like to have some tips on solving this problem:

This is my code:


#include "Bill.h"
#include "../Exceptions/InvalidArgumentException.h"



Bill::Bill(string shopName)
	if (shopName == "")
		throw(InvalidArgumentException("The shop name cannot be empty."));

	m_shopName = shopName;



#include <exception>

using namespace std;

class InvalidArgumentException : public exception
	InvalidArgumentException(const char* invalidArgument);

	const char* what() const throw();

	static size_t MaximumMessageLength()
		return 100;

	InvalidArgumentException(const InvalidArgumentException&);

	void InitializeMessage();
	void ValidateArgument(const char* invalidArgument);

	const char* m_invalidArgument;
	char m_message[100];		//TODO: Change the way of returning a const char*. That's ugly to use an automatic-allocated array.



#include <string>

#include "InvalidArgumentException.h"

//Public Methods

InvalidArgumentException::InvalidArgumentException(const char* invalidArgument)

	m_invalidArgument = invalidArgument;

const char* InvalidArgumentException::what() const throw()
	return m_message;

//Private Methods

void InvalidArgumentException::InitializeMessage()
	strcpy_s(m_message, m_invalidArgument);

void InvalidArgumentException::ValidateArgument(const char* invalidArgument)
	if (invalidArgument == 0)
		throw(std::exception("The message pointer is null."));
	else if (strlen(invalidArgument) == 0)
		throw(std::exception("The message is empty."));
	else if (strlen(invalidArgument) > MaximumMessageLength())
		throw(std::exception("The message is too long."));

The linker output is:

1>LINK : .\Output\Debug\Billzilla.exe not found or not built by the last incremental link; performing full link
1>Bill.obj : error LNK2001: unresolved external symbol "private: __thiscall InvalidArgumentException::InvalidArgumentException(class InvalidArgumentException const &)" (??0InvalidArgumentException@@AAE@ABV0@@Z)
1>.\Output\Debug\Billzilla.exe : fatal error LNK1120: 1 unresolved externals

Looks like Bill.obj can't find the constructor symbol in InvalidArgumentException.obj. It's the constructor call in the throw() of Bill.cpp that causes the error. It's been a long time using C++, and I'm unable to solve this problem. Can you help me?

InvalidArgumentException::InvalidArgumentException(class InvalidArgumentException const &)" (??0InvalidArgumentException@@AAE@ABV0@@Z)

I think the problem is that your copy ctor is declared but not defined and somewhere you are trying to make a copy of your class 'InvalidArgumentException' .

InvalidArgumentException(const InvalidArgumentException&);

so you could either provide a copy ctor definition or remove any copy attempts from your code or remove this declaration from your code so that the compiler generates it for you when needed

Edited 6 Years Ago by Agni: n/a

Thanks for the help! I didn't know that the copy constructor of a class that is thrown needs to be public.

This question has already been answered. Start a new discussion instead.