Overloading functions cross-compiler

This is the code that works fine in VS2010, but returns an error(
expected primary-expression before 'char'
) on C::B and wxDev:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
bool Contains(char* text,char* what)
	{
		int size=sizeof(text);
		int whsize=sizeof(what);	
		for(int i=0;i<size;i++)
		{	
			for(int j=0;j<whsize;j++)
			{
				if(text[i]==what[j])
				{
					return true;
				}
			}
		}
		return false;
	}

	bool Contains(char ch,char* what)
	{
		char str[]={ch,'\0'};
		
		return Contains(str,what);
	}


I defined both functions in the header(this is the implementation in the .cpp file)
What's going on here? Why do C::B and wxDev return an error here?
Last edited on
First of all your code is symantically invalid. For example the expression statement

int size=sizeof(text);

will give you the size of the pointer that is usually equal to 4 bytes on 32-bit systems not the size of the character string pointed by this pointer.
As for a synax error I do not see such an error. Myabe you made a typo when you were transfering the code from one compiler to another.
Last edited on
thx reminding me, it has to be strlen :P was kinda rushing ahead...

well all of the code was saved in file that I opened later in different IDE and the error came up...
Last edited on
I do not see the error you are talking about. You can copy your own code from here into the editor of your compiler.
Well yes but I keep getting the error...
Then you should post some context (surrounding code and line number).
The indentation in that code is way off, so that's an indicator that this isn't actually a free-standing function.
Last edited on
OK solved that...Somewhere in the code there was a define for letter 'č' that is not supported by C::B or wxDev, so it got translated to 'ch', which caused the incoming variable to be a defined constant...
Last edited on
Topic archived. No new replies allowed.