Ok, so I'm really after knowledge rather than a quick easy solution here. I am part of a team that is currently working on the development of a 'kind of' physics engine but I have hit a small wall since adapting the functionality of a class which was previously working perfectly. Basically, I have multiple classes that are responsible for the reconstruction of particular objects in different views; I wished to template one particular 'builder' class in order to reuse most of the current code but to build a different (but similar) objects.

Problem:
Since rebuilding this class I have been unable to get it to compile :(
I use a static function (defined elsewhere) call used at the bottom of the source file to register information about each builder class. I can't figure out how I'm supposed to call this function within the template class though.....(NB: This call is not made within function scope of any of the template class functions)
If I compile without template parameters then obviously I get an error, but it's not a function that is actually part of the template class! Just called within it. If I add template parameters then I get the error "expected constructor, destructor or type conversion before token'.

Any help would be greatly appreciated :)

p.s The code is of a sensitive nature so I can't really post it here. I am more than willing to demonstrate my problems with examples and perhaps some small code snippets however.

I would indeed try to make a "20-line" demo of the problem that you can post for us.

Here is the basic code that I am implementing:

#ifndef _BUILDER__
#define _BUILDER__

// Header files have been removed intentionally!!

 /*************************************************************************\
(				FORWARD DECLARATIONS	       		    )
 \*************************************************************************/

template<class T>
class Builder : public SimpleBuilderTemplate<T> {

public:
	Builder(){;}
	virtual ~Builder(){;}

 /*************************************************************************\
(				MEMBER FUNCTIONS	       		    )
 \*************************************************************************/
	

private:
	Builder(const Builder&); // Stop default
	const Builder& operator=(const Builder&); // Stop default

	void build(const T&, unsigned int, TEveElement&, const ViewContext*);


 /*************************************************************************\
(				MEMBER DATA 	       		            )
 \*************************************************************************/
};
#endif

//
// Member functions
//
template<class T> void
Builder<T>::build(const T& iData, unsigned int iIndex, TEveElement& oItemHolder, const ViewContext*)
{
	// Functionality of build removed as it is not necessary

}

template<class T> //Here is the code that is causing me problems
REGISTER_BUILDER<T>(Builder, T, "RecoBuild", ViewType::kAll3DBits);//(name, type, purpose, view)

Most of the code is actually irrelevant because I know that it works. It compiles and runs fine until I add "REGISTER_BUILDER" in which I use to store and later display information about the builder class.

I was hoping for something that I could compile and poke around at :)

Hmmm this could be a bit of a problem because that file has 7 user includes, most of which I haven't written and so don't really have the right to disclose. You can actually remove the build function because I already tested it works and tested that it works once integrated with the rest of the system. You could perhaps suggest some steps for me to take and I could post results?

The way you have declared the templated function is wrong. if your function is a void function then instead of this

template <class T>
REGISTER_BUILDER<T>(Builder, T, "RecoBuild", ViewType::kAll3DBits);//(name, type, purpose, view)

Try this

template<class T>
void REGISTER_BUILDER(Builder, T, "RecoBuild", ViewType::kAll3DBits);//(name, type, purpose, view)

When you template a class the you have to use <...> but with functions you don't. When you actually go to use the code in you program you can write

REGISTER_BUILDER<int>(Builder, 5, "RecoBuild", ViewType::kAll3DBits);

Check this link out and you should see how it got confused. http://www.cplusplus.com/doc/tutorial/templates/

Ah but this is my problem....it isn't supposed to be a function declaration :s
The function is already defined elsewhere but I wish to use it within this template class. Normally I would just do:

REGISTER_BUILDER(Builder, T, "RecoBuild", ViewType::kAll3DBits);

but obviously instead of having 'T' there would be a type such as 'reco::myType'. Without the template parameters the compiler throws a lot of errors though and when I do use them I get 'Expected constructor, destructor or type conversion' error....

Could you post the function decleration? Also the function or part of code that you are using it in.

what exactly is REGISTER_BUILDER? are you 100% sure that its a function? usually ALL_UPPERCASE names are reserved exclusively for #define macros

it would help a great deal if you could show us the definition of REGISTER_BUILDER.

Well no....it is a define macro :s

I've managed to solve my problem now. It was basically one '}' missing at the end of a function really high up in the hierarchy that was causing problems for other class further down the line.

Thanks for everyone's help and patience anyway :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.