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 3240364
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:04:36+00:00 2026-05-17T18:04:36+00:00

In the file test.cpp, I have this: template <typename T> class A { public:

  • 0

In the file test.cpp, I have this:

template <typename T>
class A
{
public:
  A(int a){};
  virtual ~A();

private:
};

class B : public A<int>
{
public:
  B(int a):A(a){};
  virtual ~B();

private:
};

int main()
{
  return 0;
}

When I compile it, I get this:

jason@jason-linux:~/Documents/ECLibrary$ g++ -g -Wall -Wextra -pedantic-errors test.cpp -o tdriver
test.cpp: In constructor ‘B::B(int)’:
test.cpp:14: error: class ‘B’ does not have any field named ‘A’
test.cpp:14: error: no matching function for call to ‘A<int>::A()’
test.cpp:5: note: candidates are: A<T>::A(int) [with T = int]
test.cpp:3: note:                 A<int>::A(const A<int>&)

I do not want a default constructor for my base class, since it doesn’t make sense in my code. I just want my derived class to perform the called constructor of the base class and do some extra construction for the extra stuff in the derived class. I’m really not sure why it is trying to call the default constructor of the base class when I’m trying to explicitly call an alternate constructor. Am I missing something here?

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-17T18:04:37+00:00Added an answer on May 17, 2026 at 6:04 pm

    You can add the template argument list to A:

    B(int a) : A<int>(a) { } 
    

    Note that the code that you have–using A without the template argument list–is valid C++. Comeau and Visual C++ 2010 both accept the code as-is.

    g++ 4.3 does not accept the code without the template argument list. Perhaps someone can test a later version of g++ or check the g++ bug database to see whether it is a known issue (I don’t regularly use g++ and am not familiar with their bug database).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is driving me crazy. I have this one php file on a test
Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);
Let's say I have a file called test.txt within the package com.test.io within my
For simplicity, i have the following file named test.jsp: <script language=javascript> alert(a$b.replace(/\$/g,k)); </script> I
For example, suppose I have a batch file called 'test.cmd' and it simply contains:
I'm writing a test for a file parser class. The parse method receives a
I have this class header //header for class. #ifndef Container_H #define Container_H #include <iostream>
I made a test file, and ran through the excel file just fine, but
I made an html file called test.html then I navigated to it as http://site.com/test.html?test1=a
I am programmatically exporting data (using PHP 5.2) into a .csv test file. Example

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.