LNK2005

I have three classes: memoryList, memoryNode, monthlyRainFallValues.
memoryNode has a function getValue(), then the monthlyRainFallValues has the gets functions for each individual item.

i.e.:
thisNode->getValue()->getMonth();

When I go to compile, studio is listing every single function for both of these with the LNK2005 error. each header file has the #pragma once guard listed.

any suggestions where I need to look to figure this out?
Only listing the first since there are over 20:

Error 1 error LNK2005: "public: class memoryNode * __thiscall memoryNode::getLink(bool)" (?getLink@memoryNode@@QAEPAV1@_N@Z) already defined in driverApp.obj C:\Users\Duke\Documents\Visual Studio 2013\Projects\BoudreauRainCalculations\BoudreauRainCalculations\memoryList.obj BoudreauRainCalculations

and here is the code:
1
2
3
4
5
6
7
memoryNode *memoryNode::getLink(bool preLink)
{
	memoryNode *link=postNode;
	if (preLink)
		link = preNode;
	return(link);
}
The error message says "already defined". That implies you defined the function in more than one place.

Have you defined the function in both the header and in a .cpp file?
Or in a header that gets included in more than once .cpp file?

Error message mentions both driverapp.obj and memorylist.obj, so I would check those .cpp files first for why getLink is included in more than one .cpp file.



Last edited on
just double checked, and other that being prototyped in the class, then actually programmed in the cpp, there is no duplication. the getLink is programmed in the node, and called in the list, the list is then called in the driver.

each Header is included in its cpp, and then also in the level above it. For example the month.h is in the month.cpp, then also in the node.h (not the node.cpp) Is that wrong?
Last edited on
Well I got it to compile at last, but here is my question. I had methods that were one or two lines, programmed in the header file. My understanding is that you can put some code in the header, as long as it short. Now that I have moved all the methods to the cpp, it loads just fine. So did my instructor not teach me a minute detail, or is that something new with 2013?
> My understanding is that you can put some code in the header, as long as it short
inline
Topic archived. No new replies allowed.