redeclaration of function that isn't there, etc

all of these error messages seem to be bogus.
but I don't know what to so with them. can't get past them. (gcc)

f:\prj\lib\strfuncs>type err.txt
strfuncs.min.cpp: In function 'int str::compare(std::__cxx11::string, std::__cxx11::string, bool, size_t)':
strfuncs.min.cpp:299:9: error: redefinition of 'int str::compare(std::__cxx11::string, std::__cxx11::string, bool, size_t)'
int compare(std::string first, std::string second, bool iCase=false, size_t firstPos=0) {
^~~~~~~
strfuncs.min.cpp:218:9: note: 'int str::compare(std::__cxx11::string, std::__cxx11::string, bool, size_t)' previously defined here
int compare(std::string first, std::string second, bool iCase=false, size_t firstPos=0) {
^~~~~~~
strfuncs.min.cpp: In function 'size_t str::find(std::__cxx11::string, std::__cxx11::string, bool, size_t)':
strfuncs.min.cpp:581:12: error: ambiguating new declaration of 'size_t str::find(std::__cxx11::string, std::__cxx11::string, bool, size_t)'
size_t find(std::string haystack, std::string needle, bool iCase=false, size_t pos=0) {
^~~~
strfuncs.min.cpp:470:27: note: old declaration 'std::vector<unsigned int> str::find(std::__cxx11::string, std::__cxx11::string, bool, size_t)'
std::vector< size_t > find(std::string haystack, std::string needle, bool iCase=false, size_t pos=0) {
^~~~
strfuncs.min.cpp: At global scope:
strfuncs.min.cpp:666:108: error: local variable 's' may not appear in this context
std::string trim(std::string s, std::string whitespaceCharSet=trimWs, size_t posStart=0, size_t posEnd=s.size()) {
^
strfuncs.min.cpp: In function 'bool str::wildcardFilepathMatchDOSWIN(std::__cxx11::string, std::__cxx11::string, bool, size_t)':
strfuncs.min.cpp:1321:99: error: 'wsub' was not declared in this scope
(!(iCase||caseInsensitiveOS) && 0==compare(filepath.substr(filepath.size()-wsub.size()),wsub,false,0))
^~~~
strfuncs.min.cpp:1321:99: note: suggested alternative: 'ws'
(!(iCase||caseInsensitiveOS) && 0==compare(filepath.substr(filepath.size()-wsub.size()),wsub,false,0))
^~~~
ws
strfuncs.min.cpp:1360:72: error: cannot convert 'std::vector<unsigned int>' to 'size_t {aka unsigned int}' in assignment
fpPos=find(filepath,wcSub,false,fpStart);
^
strfuncs.min.cpp: In function 'std::__cxx11::string str::zeropad(LD, intmax_t, std::__cxx11::string, bool, bool, bool)':
strfuncs.min.cpp:1550:77: error: cannot convert 'std::vector<unsigned int>' to 'size_t {aka unsigned int}' in initialization
size_t dotPos=nstr.find("."),ePos=find(nstr,"e",true);
^
strfuncs.min.cpp: At global scope:
strfuncs.min.cpp:1560:23: error: expected unqualified-id before 'else'
} else {//if ("-" == nstr[0])
^~~~
strfuncs.min.cpp:2122:1: error: expected '}' at end of input
}
^
f:\prj\lib\strfuncs>



Without seeing your code, it's impossible to say what is wrong.

The error messages should be giving you info about the places (files and line nos) where the duplicated definitions are.

Obviously, without seeing your code, we can't know what's wrong with it.

One possibility is that you're including header files more than once. Are you using header files without multiple inclusion guards?
Without the code it is just guessing, but could it be that you have a header file and an implementation file, where the class definition in the header file has not been properly closed?
1
2
3
4
5
6
7
class example
{

     void wonderfulfunction();

}; // <= I once by accident removed this line. The result is that every thing in that class (including the function implementation
    // in the cpp file) was interpreted as declarations. So obviously every function was being "redefined" in the cpp file. 
It is occasionally helpful to run (only) the preprocessor over your source code to help shed light on the source of ODR violations or inexplicable errors (e.g., name collisions with macros, bugs in macro definitions, or errors inserted into the source code by #include statements).

Once you do that, you can compile the resulting file (which contains the entire translation unit) to get error locations that aren't obscured by the CPP.

Check indentation and things around and inside header files; look at the whole translation unit.
This can help locate the sort of errors like Nico describes.
Last edited on
Topic archived. No new replies allowed.