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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:50:31+00:00 2026-05-26T21:50:31+00:00

I have encountered a strange error relating to template class in C++. The codes

  • 0

I have encountered a strange error relating to template class in C++. The codes run OK most of the time, but in one occasion it failed. The following is simplified codes:

template <class T>
class Class1
{
    ...
    T *func();
    ...
};

// ---------------------------------------------------------------

template <class T>
T *Class1<T>::func(...)
{
    ...
    string name = typeid(T).name();
    T *ptr = a_queue.front(); // a_queue is of type "queue<T *>"
    ptr->some_func(); // failed
    ...
}

// ---------------------------------------------------------------

Class1<Class2> class1;
class1.func();

Suppose Class1 is specialized with T is Class2 and Class3 respectively. In Class1<Class2>::func, ptr is declared as Class3 pointer in that occasion! So the type is not safe in template class?

Any idea? Thanks!

Edit:

I have added string name = typeid(T).name(), then T will be correct type (Class2), but when call the member function some_func of Class2, there is a error:

cannot access memory address at 0x10

[Solved] Final edit 2011/11/09:

I have found the problem, it is not related to template class, but caused by deleting the wrong pointer, which is not newed in the same function with delete and has been pushed into the queue!

  • 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-26T21:50:32+00:00Added an answer on May 26, 2026 at 9:50 pm

    cannot access memory address at 0x10

    That is equivalent to a NULL pointer reference. The compiler started with some T *ptr = 0 and tried to find a member (or vtable) of T at offset 0x10 so it looked at memory 0 + 0x10. So I don’t think your problem is a matter of template types but of a_queue.front() containing NULL.

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

Sidebar

Related Questions

I have been trying to output XML with PHP but encountered a strange(!) error
We have encountered a very strange class not found problem in our web app
I have encountered something very strange, simple WPF application <Window x:Class=ListBoxSelection.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow
I have encountered a strange behavior with a simple C++ class. classA.h class A
I'm working with MVC 3 and have encountered a strange error. I have customErrors='On'
I have encountered a strange issue. When I update one of my websites to
While attempting to use the CopyFile() function I have encountered a strange error. It
I have encountered a strange Invalid Packet Lenght (that is how the error is
I have encountered a strange error. I use Windows 7 x64. Visual Studio 2010
I have encountered a strange problem where if I call getString(R.string.somestringname) , from time

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.