don't need an object or class to call function?

Hi guys sorry If the wording isn't good in the question I can't think of a better choice,anyway coming from Java and spending so long with Java,I noticed that we can call functions without specifying the class name for example SDL_CreateWindow() here we don't specify the class name,

in Java even if you are calling a static method you need to specify the class name followed by a dot,myClass.doSomething();

how come this works in c++?,the function isn't local to the class it's imported using a header file

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


#include <iostream>
#include <SDL.h>

using namespace std;

int main(int argc, char* argv[])
{


	  SDL_Window *window;                    // Declare a pointer

	    SDL_Init(SDL_INIT_VIDEO);              // Initialize SDL2

	    // Create an application window with the following settings:
	    window = SDL_CreateWindow(
	        "An SDL2 window",                  // window title
	        SDL_WINDOWPOS_UNDEFINED,           // initial x position
	        SDL_WINDOWPOS_UNDEFINED,           // initial y position
	        640,                               // width, in pixels
	        480,                               // height, in pixels
	        SDL_WINDOW_OPENGL);
	   // flags - see below

}
SDL_CreateWindow() is a C function. It is not a member of a C++ class, therefore no class name is needed.
To repeat AbsAnon's words, and really flog the dead horse, in Java all functions are part of a class. In C++ (not just C) they don't have to be. You can create functions that are not part of a class.

how come this works in c++?
Because C++ is a different programming language with different rules. It's not Java. It's different.
Topic archived. No new replies allowed.