Issues with IDE Linker? Why is this happening, and how do i fix it?

Started by
7 comments, last by Alessio1989 9 years ago

Hello, recently i separated one file intro multyple, now i am having compiler complain some of classes having unknown variables.


//The function
int Object::GetAttackDamage()
{
	int damage = 0;
	if (inventory != NULL)
	{
		BaseItem * equWep = unit->GetEquipedWeapon();
		if (equWep != NULL)
		{
			damage += equWep->wepDamage;
		}
	}

	if(unit)
		damage += unit->attackDamage;
	return damage;
}

//The error
C:/Prog/Code/src/Objects.cpp:155:22: error: 'class BaseItem' has no member named 'wepDamage'
damage += equWep->wepDamage; 

I can confirm that Objects.cpp includes Inventory.h which includes BaseItem.h Which has class BaseItem which inherites BaseItemWeapon which has this member, its publicly inherited so its visible. I don't know whats happening, or what have i done wrong sad.png

Here are raw cut outs of data from project, its clearly visible it is correct AFAIK.

http://pastebin.com/QcdcpXZM

What are common issues, and how would i go solving this issue? I have no clue what to do...

Advertisement

Maybe the include guards on lines 21, 22, 46, 47 and the #endif at the end of the file are messing things up, maybe they shouldnt be there at all after you moved things around?

Also where is this Object class?

Your BaseItem.h and Inventory.h have the same include guards. So Inventory.h including BaseItem.h will actually never include the content of BaseItem.h.

Just rename the include guard to BASEITEM_H.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Or don't use include guards like that because the Big Three of compilers a normal person is likely to encounter all support '#pragma once'.

Oh god, i forgot to update, i fixed it. Header guard had name conflict...

And yes, thank you for help. I decided to find issue my self, and i forgot about this post. I Was stuck for some time, and i was getting nowhere so i felt supper down. I really appreciate your help!

I also strongly recommend using #pragma once instead of include guards to avoid this sort of thing. It gets especially silly in larger projects where you'll often have multiple files with the same name.

I also strongly recommend using #pragma once instead of include guards to avoid this sort of thing. It gets especially silly in larger projects where you'll often have multiple files with the same name.

But isn't #pragma once MSVC only? is it crossplatform?, if not. That's why i use #include/

#pragma once is not msvc only like it once was. Any compiler worth it's salt supports it. I think it's even recommended by the GCC community to use pragma once.

Yes, it's not standard, but it is the most standard non-standard standard I know. ;)

Too many projects; too much time

Even IBM XL supports #pragma once since version 13.1.1. The only "big" (euphemism!) missing should be solaris IDE...

"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/

This topic is closed to new replies.

Advertisement