Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6912067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:02:36+00:00 2026-05-27T09:02:36+00:00

I have a header file… #include <SFML\Graphics.hpp> #include <SFML\Graphics\Drawable.hpp> #include <SFML\System.hpp> #include <iostream> #ifndef

  • 0

I have a header file…

#include <SFML\Graphics.hpp>
#include <SFML\Graphics\Drawable.hpp>
#include <SFML\System.hpp>
#include <iostream>

#ifndef _SPRITE_H_
#define _SPRITE_H_

namespace Engine 
{
    template <class T>
    class Sprite
    {
        sf::Vector2<T> * vector;
        sf::Sprite * sprite;

    public:
        Sprite(sf::Vector2<T> vect, sf::Sprite spr) 
        { 
            this->sprite = spr;
            this->vector = vect;            
        }
        ~Sprite();
        bool Draw(T x, T y, T rotate = 0);
        sf::Image GetImage()
        {
            return this->sprite->GetImage();
        }
    };
};

#endif _SPRITE_H_

And a source file…

#include <SFML/Graphics.hpp>
#include <SFML/Config.hpp>

#include "sprite.h"

template <typename T>
Sprite(sf::Vector2<T> vector, sf::Sprite sprite) 
{
    this->sprite = sprite;
    this->vector = vector;
}

template <typename T>
bool Draw(T x, T y, T rotate) 
{
    return false;
}

In VS 2010, when I compile VC++ I get the following errors:

Error   2   error C2143: syntax error : missing ';' before '<'  c:\users\owner\documents\visual studio 2010\projects\engine2\engine2\sprite.cpp 7   1   Engine2
Error   3   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\users\owner\documents\visual studio 2010\projects\engine2\engine2\sprite.cpp 7   1   Engine2
Error   4   error C2988: unrecognizable template declaration/definition c:\users\owner\documents\visual studio 2010\projects\engine2\engine2\sprite.cpp 7   1   Engine2
Error   5   error C2059: syntax error : '<' c:\users\owner\documents\visual studio 2010\projects\engine2\engine2\sprite.cpp 7   1   Engine2
Error   6   error C2059: syntax error : ')' c:\users\owner\documents\visual studio 2010\projects\engine2\engine2\sprite.cpp 7   1   Engine2
Error   7   error C2143: syntax error : missing ';' before '{'  c:\users\owner\documents\visual studio 2010\projects\engine2\engine2\sprite.cpp 15  1   Engine2
Error   8   error C2447: '{' : missing function header (old-style formal list?) c:\users\owner\documents\visual studio 2010\projects\engine2\engine2\sprite.cpp 15  1   Engine2

I am a total noob to C++ (coming from C#), and have been having issues compiling this simple file as a means to at least learn the syntax before I continue on. As you can see, all I’m trying to do is reference a template from a header file to a source file, so that template reference effects all of my methods.

What am I doing wrong? I’ve tried to understand these compiler messages, but I’m having trouble decrypting them.

Update

Followed suggestion: took care of almost everything, except for this:

Error   1   error C2995: 'Engine::Sprite<T>::Sprite(sf::Vector2<T>,sf::Sprite)' : function template has already been defined    c:\users\owner\documents\visual studio 2010\projects\engine2\engine2\sprite.cpp 12  1   Engine2
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:02:37+00:00Added an answer on May 27, 2026 at 9:02 am

    Since Sprite is inside Engine, it should be

    template <typename T>
    Engine::Sprite<T>::Sprite(sf::Vector2<T> vector, sf::Sprite sprite)
    { ... }
    

    And

    template <typename T>
    bool Engine::Sprite<T>::Draw(T x, T y, T rotate)
    {
        return false;
    }
    

    Or, as @jli suggests, put it inside the namespace Engine too:

    namespace Engine {
        template <typename T>
        Sprite<T>::Sprite(sf::Vector2<T> vector, sf::Sprite sprite)
        { ... }
    
        template <typename T>
        bool Sprite<T>::Draw(T x, T y, T rotate)
        {
            return false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a header file like this: #ifndef __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #define __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #ifdef _DEBUG //
I have a header file with all the enums listed (#ifndef #define #endif construct
I have C++ project (VS2005) which includes header file with version number in #define
I have a header file that has some forward declarations but when I include
I have a header file MyNameSpace.h where i use namespace as under: namespace NameSpace1
I have a header file in which I wish to use a namespace alias
Let's say I have a header file called inclusions.h that has all the #include
Let's say i have a header file Snake.h: #include SnakeBodyPart.h #include GUI.h //... And
I have a header file (head.h) in which I define the boolean value: bool
I have a header file like so: #pragma once #include gamestate.h #include ExitListener.h class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.