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

  • Home
  • SEARCH
  • 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 3692144
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:13:43+00:00 2026-05-19T04:13:43+00:00

Got this in char.h #ifndef _CHAR_H_ #define _CHAR_H_ #include <stdio.h> template <unsigned int TChar>

  • 0

Got this in “char.h”

#ifndef _CHAR_H_
#define _CHAR_H_

#include <stdio.h>

template <unsigned int TChar>



class Char
{
public:
 Char(){ *m_data=0; m_len=-1; }

private:
  char m_data[TChar+1];
 int m_len;
}; 

#endif

Now with this simple test :

#include "char.h"


void test(Char<TChar> &oo)
{
  //...
}


int main(int argc, char *argv[])
{
  Char<80> gg;

  return 0;
}

I get with gcc :
TChar was not declared in that scope !?
I don’t understand, the declaration is in the .h ??

Thanks…

  • 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-19T04:13:43+00:00Added an answer on May 19, 2026 at 4:13 am

    The full implementation of a template class must be in that template class’s header (otherwise you are likely to get a linker error).
    The compiler needs to have access to the entire template definition (not just the signature) in order to generate code for each instantiation of the template, so you need to move the definitions of the functions to your header. (Inclusion Model).

    You have placed the definition correctly. 🙂

    However in void test(Char<TChar> &oo) the compiler doesn’t know what TChar is. Try adding template <unsigned int TChar> above the definition

    template <unsigned int TChar>
    void test(Char<TChar> &oo){
      // ... stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I got this in Message.h: #ifndef _MESSAGE_H_ #define _MESSAGE_H_ #include <stdio.h> #include <string.h>
I got this interface I've written: #ifndef _I_LOG_H #define _I_LOG_H class ILog { public:
So I've got this. #define MAX_MENU_OPTIONS 1 typedef struct _NEW_MENU_OPTION { char* name; int
I've got this header (redone from a boost asio example): #ifndef MSGSRV_H_ #define MSGSRV_H_
I got a struct for client and server like this: { char type; int
I'm trying to create a Delphi version of this algorithm: void PWSfileV3::StretchKey(const unsigned char
So I ve got this: char table1[10^length][length]; char table2[10^length][length]; And compiler doesn't let me
I've got this simple piece of code: char data[4] = { 0x13, 0x34, 0xad,
I've got this sample code: struct A { int foo() { return 27; }
I got this message: expected 'void **' but argument is of type 'char **'

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.