GCC编译错误 There are no arguments to 'X' that depend on a template parameter, so a declaration of 'X' m

No arguments that depend on a template parameter

There are no arguments to 'X' that depend on a template parameter, so a declaration of 'X' must be available

Aside: I have a C++ program of 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 call SetMembership.

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 a member 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);
	}

	// ...
};

One of 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.


更多的看

http://stackoverflow.com/questions/9941987/there-are-no-arguments-that-depend-on-a-template-parameter

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值