CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: 'player::player': no overloaded function takes 4 arguments

  1. #1
    Join Date
    Nov 2020
    Posts
    1

    'player::player': no overloaded function takes 4 arguments

    Hello good day,
    I am an engineering student who is starting with programming in c ++, i am learning the Overloading operators, I don't remember how to fix this problem...


    MAIN: .........................................................................................................................................................................................................................
    Code:
    //Game general information
    #define SCREEN_WIDTH 800
    #define SCREEN_HEIGHT 600
    
    Vector2 mousePos;
    
    int main(int, char*[])
    {
    #pragma region INIT
    	// --- INIT SDL ---
    	if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
    		throw "No es pot inicialitzar SDL subsystems";
    	// --- INIT TTF ---
    	if (TTF_Init() != 0)
    		throw "No es pot inicializtar TTF";
    
    	// --- WINDOW ---
    	SDL_Window *m_window{ SDL_CreateWindow("SDL...", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN) };
    	if (m_window == nullptr)
    		throw "No es pot inicialitzar SDL_Window";
    
    	// --- RENDERER ---
    	SDL_Renderer *m_renderer{ SDL_CreateRenderer(m_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC) };
    	if (m_renderer == nullptr)
    		throw "No es pot inicialitzar SDL_Renderer";
    
    	//-->SDL_Image 
    	const Uint8 imgFlags{ IMG_INIT_PNG | IMG_INIT_JPG };
    	if (!(IMG_Init(imgFlags) & imgFlags)) throw "Error: SDL_image init";
    #pragma endregion
    
    	//-->SDL_Mix | -->SDL_TTF
    	const Uint8 mixFlags(MIX_INIT_MP3 | MIX_INIT_OGG);
    
    	// --- SPRITES ---
    #pragma region Sprites
    	//Background
    	SDL_Texture* bgTexture{ IMG_LoadTexture(m_renderer, "../../res/img/bg.jpg") };
    	if (bgTexture == nullptr) throw "Error: bgTexture init";
    	sprite testSprite("../../res/img/kintoun.png", 500, 500, 2);
    
    	SDL_Rect bgRect{ 0, 0,SCREEN_WIDTH, SCREEN_HEIGHT };
    
    	// Player
    	SDL_Texture* playerTexture{ IMG_LoadTexture(m_renderer, "../../res/img/kintoun.png") };
    	if (bgTexture == nullptr) throw "Error: plTexture init";
    	SDL_Rect plRect{ 0,0, 100, 100 };
    
    #pragma endregion
    
    
    ------------------------------------------------------------------------------------------------------------------------------------------------------------THIS ZONE
    	//-->Animated Sprite ---
    #pragma region Animation
    	animatedSprite playerAnim1("../../res/img/sp01.png", 200, 200, 6, 6, 1);
    	animatedSprite playerAnim2("../../res/img/sp02.png", 200, 200, 6, 6, 1);
    	animatedSprite testAnim("../../res/img/spCastle.png", 10, 10, Vector2(0, 0), Vector2(96, 32), 96, 12, 8);
    
    ------------------------------------------------------------------------------------------------------------------------------------------------------------THIS ZONE
    
    #pragma endregion
    
    	// --- PLAYERS ---
    	player player1(&playerAnim1, 200, 200, 10);
    	player player2(&testAnim, 500, 500, 2);
    
    	// --- TEXT ---
    #pragma region Buttons
    	SDL_Surface *textSurface{ TTF_RenderText_Blended(TTF_OpenFont("../../res/ttf/doubledecker.ttf", 40), "test", SDL_Color{255,255,255,255}) };
    
    	Button exitButton(m_renderer, textSurface, SDL_Color{ 255, 0, 0, 255 }, SDL_Color{ 0, 0, 0, 255 }, "../../res/ttf/doubledecker.ttf", "Exit", 500, 370, 40);
    
    	Button musicButton(m_renderer, textSurface, SDL_Color{ 49, 55, 181, 255 }, SDL_Color{ 0, 0, 0, 255 }, "../../res/ttf/doubledecker.ttf", "Music", 300, 370, 40);
    
    	Button playButton(m_renderer, textSurface, SDL_Color{ 0, 255, 0, 255 }, SDL_Color{ 0, 0, 0, 255 }, "../../res/ttf/doubledecker.ttf", "Play", 100, 370, 40);
    
    	bool mouseClicked = false;
    	bool playToggle = false;
    #pragma endregion
    
    	// --- AUDIO ---
    #pragma region Audio
    	if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == -1)
    	{
    		throw "Unable to initialize SDL_mixer audio systems";
    	}
    	Mix_Music *soundtrack{ Mix_LoadMUS("../../res/au/mainTheme.mp3") };
    	if (!soundtrack) throw "Unable to load the Mix_Music soundtrack";
    	Mix_VolumeMusic(MIX_MAX_VOLUME / 2);
    	Mix_PlayMusic(soundtrack, -1);
    #pragma endregion
    
    	// --- TIME  ---
    	timer testTimer(5);
    
    	// --- GAME LOOP ---
    	bool releaseMouse = true;
    	SDL_Event event;
    	bool isRunning = true;
    	bool yes = true;
    
    	// --- INPUTS ---
    	inputs gInp;
    
    	while (isRunning)
    	{
    		std::cout << testTimer.updateTimer() << std::endl;
    		while (SDL_PollEvent(&event)) 
    		{
    			switch (event.type) 
    			{
    			case SDL_MOUSEBUTTONDOWN:
    				mouseClicked = true;
    				player2.setNewAnim(animatedSpriteSet(Vector2(0, 32), Vector2(96, 64)));
    				break;
    			case SDL_MOUSEBUTTONUP:
    				mouseClicked = true;
    				player2.setNewAnim(animatedSpriteSet(Vector2(0, 0), Vector2(96, 32)));
    				break;
    			default:;
    			}
    		}
    
    		// --- INPUT ---
    		gInp.getKeyboardInputs();
    
    		// --- UPDATE ---
    		player1.updatePlayer(gInp.keyboard, 0);
    		player2.updatePlayerTest(gInp.keyboard, 1);
    
    		// - Background - 
    		SDL_RenderCopy(m_renderer, bgTexture, nullptr, &bgRect);
    		//testSprite.renderSprite();
    		player1.renderPlayer();
    		player2.renderPlayer();
    		SDL_RenderPresent(m_renderer);
    	}
    
    	// --- DESTROY ---
    	SDL_DestroyTexture(bgTexture);
    	IMG_Quit();
    	SDL_DestroyRenderer(m_renderer);
    	SDL_DestroyWindow(m_window);
    
    	// --- QUIT AUDIO ---
    	Mix_CloseAudio();
    	Mix_Quit();
    
    	// --- QUIT ---
    	SDL_Quit();
    
    	return 0;
    }
    PLAYER.H:.........................................................................................................................................................................................................................
    Code:
    struct player
    {
    	animatedSprite *playerSprite;
    
    	int posX, posY;
    	int velX{ 0 }, velY{ 0 };
    	int speed = 0;
    
    	player(animatedSprite *givPlayerSprite, int givPosX, int givPosY, int givSpeed);
    
    	void setNewAnim(animatedSpriteSet newAnim);
    
    	void updatePlayerSprite();
    
    	void updatePlayerSpriteTest();
    
    	void movePlayer(int addX, int addY);
    
    	void checkPlayerInputs(bool *givKeys, int playerNum);
    
    	void updatePlayer(bool *givKeys, int playerNum);
    
    	void updatePlayerTest(bool *givKeys, int playerNum);
    
    	void renderPlayer();
    };
    PLAYER.CPP:.........................................................................................................................................................................................................................
    Code:
    #include "Utils.h"
    #include "Animated_sprite.h"
    #include "SpriteSet.h"
    #include "Constants.h"
    #include "Collisions.h"
    #include "Player.h"
    
    player::player(animatedSprite *givPlayerSprite, int givPosX, int givPosY, int givSpeed)
    {
    	playerSprite = givPlayerSprite;
    	posX = givPosX;
    	posY = givPosY;
    	speed = givSpeed;
    }
    
    void player::setNewAnim(animatedSpriteSet newAnim)
    {
    	playerSprite->setNewAnim(newAnim);
    }
    
    void player::updatePlayerSprite()
    {
    	playerSprite->updateSprite();
    }
    
    void player::updatePlayerSpriteTest()
    {
    	playerSprite->updateSpriteTest();
    }
    
    void player::movePlayer(int addX, int addY)
    {
    	posX += addX;
    	posY += addY;
    	updatePlayerSprite();
    	playerSprite->setPos(posX, posY);
    }
    
    void player::checkPlayerInputs(bool *givKeys, int playerNum)
    {
    	switch (playerNum)
    	{
    	case 0:
    		if (givKeys[(int)keyPressed::UP])
    		{
    			velY = -1;
    		}
    		else if (givKeys[(int)keyPressed::DOWN])
    		{
    			velY = 1;
    		}
    		else
    		{
    			velY = 0;
    		}
    		if (givKeys[(int)keyPressed::LEFT])
    		{
    			velX = -1;
    		}
    		else if (givKeys[(int)keyPressed::RIGHT])
    		{
    			velX = 1;
    		}
    		else
    		{
    			velX = 0;
    		}
    		break;
    	case 1:
    		if (givKeys[(int)keyPressed::W])
    		{
    			velY = -1;
    		}
    		else if (givKeys[(int)keyPressed::S])
    		{
    			velY = 1;
    		}
    		else
    		{
    			velY = 0;
    		}
    		if (givKeys[(int)keyPressed::A])
    		{
    			velX = -1;
    		}
    		else if (givKeys[(int)keyPressed::D])
    		{
    			velX = 1;
    		}
    		else
    		{
    			velX = 0;
    		}
    		break;
    	default:
    
    		break;
    	}
    }
    
    void player::updatePlayer(bool *givKeys, int playerNum)
    {
    	checkPlayerInputs(givKeys, playerNum);
    
    	if (velX != 0 || velY != 0)
    	{
    		updatePlayerSprite();
    		posX += (velX * speed);
    		posY += (velY * speed);
    		playerSprite->setPos(posX, posY);
    	}
    }
    
    void player::updatePlayerTest(bool *givKeys, int playerNum)
    {
    	checkPlayerInputs(givKeys, playerNum);
    
    	if (velX != 0 || velY != 0)
    	{
    		updatePlayerSpriteTest();
    		posX += (velX * speed);
    		posY += (velY * speed);
    		playerSprite->setPos(posX, posY);
    	}
    }
    
    void player::renderPlayer()
    {
    	playerSprite->renderSprite();
    }
    If someone could help me I would be very grateful.
    Last edited by VictorN; November 2nd, 2020 at 01:56 PM. Reason: added CODE tags

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,844

    Re: 'player::player': no overloaded function takes 4 arguments

    First your post was absolutely unreadable cause you used neither the CODE tags, nor the proper code formatting/indentations.
    Second: although I added the code tags in your post it is still not clear what (and where) your problem is. Please, clarify it!
    Victor Nijegorodov

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,602

    Re: 'player::player': no overloaded function takes 4 arguments

    I don't see an obvious problem. Is player.h #include(d) in Main?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)