Defined operator error?

Here's the error I get when I run this :


1
2
3
4
5
6
7
8

====== Build started: Project: SDLProject, Configuration: Debug Win32 ======
  main.cpp
c:\users\aarons\documents\visual studio 2010\projects\sdlproject\sdlproject\main.cpp(25): error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
          c:\microsoft visual studio 10.0\vc\include\system_error(425): could be 'bool std::operator !=(const std::error_code &,const std::error_condition &)'
          c:\microsoft visual studio 10.0\vc\include\system_error(432): or       'bool std::operator !=(const std::error_condition &,const std::error_code &)'
          while trying to match the argument list '(std::string, int)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Here is my classes code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "SDL.h"
#include <iostream>
#include <string>

using namespace std;

// The attributes of the screen
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int BPP = 32;

// Image loading function
SDL_Surface* loadImage (std::string fileName) {

	// Create temp image
	SDL_Surface* tempImage = NULL;

	// Create new image
	SDL_Surface* newImage = NULL;

	// Load the temp image
	tempImage = SDL_LoadBMP (fileName.c_str());

	// Check if the image was successfully loaded and swap with correct bits per pixel
	if (fileName != NULL) {

		// Create the new optimized image
		newImage = SDL_DisplayFormat (tempImage);

		// Free the old unused image
		SDL_FreeSurface (tempImage);
	}

	return (newImage);
}

int main (int argc, char* args[])
{
	// The Images
	SDL_Surface* background = NULL;
	SDL_Surface* helloWorld = NULL;
	SDL_Surface* screen = NULL;

	// Initialize and start SDL
	SDL_Init (SDL_INIT_EVERYTHING);

	// Setup the screen
	screen = SDL_SetVideoMode (SCREEN_WIDTH, SCREEN_HEIGHT, BPP, SDL_SWSURFACE);

	// Load image
	helloWorld = SDL_LoadBMP ("helloWorld.bmp");

	// Apply image to the buffer
	SDL_BlitSurface (helloWorld, NULL, screen, NULL);

	// Update screen
	SDL_Flip (screen);

	// Pause SDL
	SDL_Delay (4000);

	// Free loaded image
	SDL_FreeSurface (helloWorld);

	// Stop SDL
	SDL_Quit ();
	return 0;
}


The error is on line : 25 just the "!=".

Also can someone explain in detail on why this is happening? Thanks
fileName is not a pointer nor any other type that you can compare to zero (=NULL).
You probably meant !fileName.empty().
You are meant to make sure the tempImage != NULL after you do SDL_LoadBMP to check if the SDL *Surface loaded correctly, not the filename.
Topic archived. No new replies allowed.