如何解决NO ARGUMENTS THAT DEPEND ON A TEMPLATE PARAMETER

Aside: I have a C++ prograof moderate complexity that I have to return to every 12-18 months to fix an obscure bug or add a modest festure. And every time, I spent one or two days just trying to get the thing build with the latest compiler, which picks up previously legal code and decides to whine about it, generating dozens of errors.

This is not the fault of the compiler. This is the fault of C++ for being so sloppy and complex. This is why C++ should just die and give way to Java.

The Error

Compiling a templated class that "worked previously" (under gcc3.3. as opposed to 4.x), an error was thrown on a previously acceptable and non-templated member:

/Users/agapow/Desktop/mloc/ComboMill.h:188: error: there are no arguments to 'SetMemberShip'
that depend on a template parameter, so a declaration of 'SetMemberShip' must be available

Huh. A simplfied version of the class looks like this:

template  class ComboMill
{
	// ...
	
	void SetMembership (bool iIsMember)
	{
		for (int i = 0; i < mMembership.size(); i++)
		{
			mMembership[i] = iIsMember;
		}
	}
	
	void First ()
	{
		// error on next line
		SetMembership (false);
	}

	// ...
};

SetMembership is called by a number of other methods to toggle the state of set members. But that isn't the problem - the problem occurs where other methods go to callSetMembership.

Solution

It's a tough error to google for, but basically C++ is being stricter about how it identifies what you are calling. Where previously a symbol "X" would be implicitly taken to refer to amember or method "X" on the parent class, here C++ is insisting that you make it explicit. Thus it can easily be fixed by writing:

	void First ()
	{
		// error on next line
		this->SetMembership (false);
	}

	// ...
};

Onof the criticisms made about Python is that you have to explicitly member access qualify with "self". It seems C++ is also not longer immune form this.

 

简而言之,这一问题是因为compiler在不断更新出现的,要解决这一问题,只需要在出问题的函数前加上this->即可

原文链接: https://www.cnblogs.com/york-hust/archive/2012/05/29/2524666.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    如何解决NO ARGUMENTS THAT DEPEND ON A TEMPLATE PARAMETER

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/51410

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 上午2:58
下一篇 2023年2月9日 上午2:58

相关推荐