3

I am getting this error when I compile with GCC:

error: declaration of 'static int utils::StringUtils::SplitString(const std::string&, const std::string&, std::vector<std::basic_string<char> >&, bool)' outside of class is not definition 

Code:

Header:

namespace utils { /* * This class provides static String utilities based on STL library. */ class StringUtils { public: /** * Splits the string based on the given delimiter. * Reference: http://www.codeproject.com/Articles/1114/STL-Split-String */ static int SplitString( const std::string& input, const std::string& delimiter, std::vector<std::string>& results, bool includeEmpties = true ); }; }; 

Source:

namespace utils { int StringUtils::SplitString( const std::string& input, const std::string& delimiter, std::vector<std::string>& results, bool includeEmpties ); { .... } } 

2 Answers 2

11

Take the semi-colon off the end of the definition in your source file! Copy-paste error =)

Sign up to request clarification or add additional context in comments.

2 Comments

could you explain why the semicolon caused the error, what is the meaning of the error?
Because the syntax for function definitions do not have a semi-colon before the body of the function. This is a super common mistake that's usually from copy/pasting the declaration from a header, then defining the function body and forgetting to remove the semi-colon from the copy/pasted declaration.
6

I believe you need to lose that semicolon in your source file. Should be:

namespace utils { int StringUtils::SplitString( const std::string& input, const std::string& delimiter, std::vector<std::string>& results, bool includeEmpties ) // <--- No more semi-colon! { .... } } 

9 Comments

Do you mean the header file? The one you copied doesn't have a semicolon on the end.
@CodeGuru, Right - I was pasting what the source file should be
@Code-Guru: yeah, Eric showed the corrected definition from the source file by omitting the semi-colon which was there in the original post.
@paddy I don't see a semicolon in that part of the code in the OP...and it hasn't been edited. However, I see one at the end of the snippet that declares the class (which is presumably a header file).
@Code-Guru, that's odd because it really is there! Perhaps the DIV element is being clipped poorly, or you need to scroll horizontally.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.