Thread: G++ Giving Me a Cryptic Error Message

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    30

    G++ Giving Me a Cryptic Error Message

    Here's the error message I get (line 50): passing 'const std::vector<SDL_Surface*>' as 'this' argument of 'void std::vector<_Tp, _Alloc>:: push_back(const value_type&) [with _Tp = SDL_Surface*, _Alloc = std::allocator<SDL_Surface*>, value_type = SDL_Surface*]' discards qualifiers

    Code:
    #ifndef CHARACTER_DEFINE_H
    
    #include <vector>
    #include <iostream>
    #include <fstream>
    #include <cstdarg>
    #include "SDL/SDL.h"
    //#include "SDL_gfxPrimitives.h"
    #include "gl/gl.h"
    #include "gl/glu.h"
    
    
    SDL_Surface* Load_fBMP(const char* filepath, const bool alphaon);
    
    
    class Entity{
    
    	void setVisible(){
    
    	}
    
    };
    
    class Dynamic_Entity : public Entity{
    
    	std::vector< SDL_Surface* > frame_data;
    
    public:
    
    	void newFrame(const char* filepath, const bool format=true, const bool alphaon=true)const{
    
    		SDL_Surface* frame;
    
    		if(format){
    			frame=Load_fBMP(filepath, alphaon);
    		}else{
    			frame=SDL_LoadBMP(filepath);
    		}
    
    		frame_data.push_back(frame);
    	}
    
    };
    
    class Dynamic_Char : public Dynamic_Entity{
    
    public:
    
    	Dynamic_Char(){
    
    	}
    
    };
    
    #endif

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    There's no line 50 in the code you pasted, but: the message isn't that cryptic: you're calling push_back() on a const vector, which is not something you would normally do with a const vector.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    30
    Quote Originally Posted by tabstop View Post
    There's no line 50 in the code you pasted, but: the message isn't that cryptic: you're calling push_back() on a const vector, which is not something you would normally do with a const vector.
    Ah, what a noob error! I removed the const qualifier from the function and it compiles fine; thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler giving error
    By Nathan the noob in forum C++ Programming
    Replies: 2
    Last Post: 06-26-2008, 06:55 AM
  2. Cryptic debug error
    By eaane74 in forum C++ Programming
    Replies: 9
    Last Post: 11-19-2007, 12:42 PM
  3. GCC compiler giving syntax error before 'double' error
    By dragonmint in forum Linux Programming
    Replies: 4
    Last Post: 06-02-2007, 05:38 PM
  4. RegQueryValueEx Giving error 234
    By Narcose in forum C Programming
    Replies: 4
    Last Post: 07-14-2006, 10:16 AM
  5. WSAGetLastError() not giving error
    By Hunter2 in forum Networking/Device Communication
    Replies: 1
    Last Post: 08-04-2003, 01:03 PM