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
#include <iostream>
#include <SDL.h>
usingnamespace 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
}
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.