# inlin[ing] class members

This topic is 4217 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I get an error when inlining a class member: "... error LNK2001: unresolved external symbol "public: void __thiscall CVector2::Set(float,float)". SomeClass.h
class CVector2
{
public:
CVector2();
CVector2(...);
inline Set(float x, float y);
};


SomeClass.cpp
CVector2::CVector2() { ... }

CVector2::CVector2(...) { ... }

inline CVector2::Set(float x, float y) { ... }


According to MSDN this is the correct syntax for inlining member functions. Could you correct me as to any missunderstanding I might have here in my code and my understanding of this behavior with inlining. Thanks, Sabrina

##### Share on other sites

In order to case down this problem do you have any ideas or tips on what to look for when finding the cause of is error?

Thanks.

Sabrina

##### Share on other sites
The error is most likely due to the fact the Set(...) does not have a return type. Try:
inline void Set(float x, float y);inline void CVector2::Set(float x, float y) { ... }

##### Share on other sites

"Set(...)" does have a return type. Sorry about that. (I should have just copyied and pasted).

class CVector2
{
public:
CVector2();
CVector2(...);
inline void Set(float x, float y);
};

inline void CVector2::Set(float x, float y) { ... }

##### Share on other sites
Inline functions should be declared and defined in the header file. Move the code from the .cpp file to the .h file and it should work. Also take a look at the C++ FAQ lite's page on inline functions, specifically this section.

##### Share on other sites

Thanks for the help and link Will F.

I did read a few thing defining them directly in the .h file. I have always been taught to split files into .h and .cpp. I was hoping I keep the .h and .cpp and still use the inlining. Guess I have to break my 'rules'. :)

Thanks again guys!

Sabrina

##### Share on other sites
Do it like this:

class CVector2
{
public:
CVector2();
CVector2(...);
void Set(float x, float y);
};

inline void CVector2::Set(float x, float y) { ... }

if you don't want the inline functions defined in your header, like me, as I hate the code bloat in the header... Put it in an inline file you include after the class... Like

class CVector2
{...}

#include "CVector2.inl"
...

Also, hungerian notion is bad. You don't need a C infront of a Vector honestly. Its like you don't need a p infront of a pointer. What if its not a pointer in a few months?

##### Share on other sites
well that's odd... I was able to do this without any problems... here's my code:

	public class BLP																				// The big daddy, all the functionality. Every function WILL throw errors if something's off. Probably a good idea to catch them! ~.^	{		BLPData Data;																				// Most of the actual data.		// CatchError()																				// Internal. Function called when an exception is thrown.						// >>all the fun utility functions like...		inline void ImportDXT3FormatFromFileStream(IO::FileStream ^FS);								// Internal. Decompresses the DXT3 data found in the file stream FS and puts the image data into this->Data.ImageData. The current file position MUST be the start of the data.		inline void ImportDXT1FormatFromFileStream(IO::FileStream ^FS);								// Internal. Decompresses the DXT1 data found in the file stream FS and puts the image data into this->Data.ImageData. The current file position MUST be the start of the data.		inline void ImportPalettedDataFromFileStream(IO::FileStream ^FS);							// Internal. Reads in paletted data to this->Data.ImageData. The current position MUST be the start of the pixel indicees. This reads in all known 8bit paletted types, and this->Type MUST be set before this is called!		inline void SaveDXT3FormatToFileStream(IO::FileStream ^FS);									// Internal. Compresses the data in Data.ImageData into DXT3 format, building the header and palette data, then outputting everything to the file stream. The current file position MUST be the start of the file.		inline void SaveDXT1FormatToFileStream(IO::FileStream ^FS);									// Internal. Compresses the data in Data.ImageData into DXT1 format, building the header and palette data, then outputting everything to the file stream. The current file position MUST be the start of the file.		inline void SavePalettedDataToFileStream(IO::FileStream ^FS);								// Internal. Compresses the data in Data.ImageData into 8bit paletted format, building the header and palette, then outputting it into the file stream. The current file position MUST be the start of the file. This saves all known 8bit paletted types, and this->Type MUST be set before this is called!	//...	};// later in the cpp file...inline void SaveDXT3FormatToFileStream(IO::FileStream ^FS){	// ...}// etc...

That's odd... but then I'm using .NET for this, so... who knows! hmm...

• 9
• 13
• 41
• 15
• 14