Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am looking at a legacy code and always see such coding style:

struct SHomog
	{
	public:
		SHomog(T _x=0, T _y=0, T _w=1)
     	{ 
          x=_x; y=_y; w=_w;
        };	<=== this semicolon causes any issue?

		T x;
		T y;
		T w;
	};


in my understanding, this semicolon following } sign will not cause any issue, but this full code page is put into a header file and filled with such extra semicolons and I suspect it is causing issue.

any advice and experience to share?

What I have tried:

one error message is as below:
Quote:
Severity Code Description Project File Line Suppression State
Error C2334 unexpected token(s) preceding '{'; skipping apparent function body
Posted
Updated 25-Mar-21 8:46am
v2

1 solution

That semicolon is redundant but shouldn't cause a problem. If I add
typedef int T;
and remove your question from the code, it compiles without any warnings at all under VS2017.

The convention is usually to use an underscore in a class member, not a parameter, but I don't see anything wrong with the code.
 
Share this answer
 
Comments
Southmountain 25-Mar-21 15:15pm    
sorry I skipped few statements as this:
template <class T>
class TLineApproximator  
{
public:
	//! \name Structures and typedefs
	//@{
	//! 2D homogenous point
	struct SHomog
	{
	public:
		SHomog(T _x=0, T _y=0, T _w=1)	{ x=_x; y=_y; w=_w;};	
			T x;
			T y;
			T w;
     	};
//skip few lines
Greg Utas 25-Mar-21 15:26pm    
I can't see how it would matter if it's located in a template, although the template needs a closing };
Southmountain 29-Mar-21 12:20pm    
thank you for your input:) I think I find the reason: the code used template style before 2003, now it has conformance issue...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900