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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:06:17+00:00 2026-05-21T02:06:17+00:00

My second question today is similar to the first one. What is wrong in

  • 0

My second question today is similar to the first one. What is wrong in this code?

#include <vector>

template <typename Item>
struct TItemsList
{
    typedef std::vector <Item> Type;
};

Container of objects:

template <typename Item>
class Container
{
    protected:
            typename TItemsList <Item>::Type items;
public:
    Item & operator [] ( int index ) {return items[index];}
    ...
    //Other functions
};

//Specialization
template <typename Item>
class Container <Item *>
{
    protected:
            typename TItemsList <Item>::Type items;
public:
    Item * operator [] ( int index ) {return items[index];}
    ...
    //Other functions needs to be specialized
};

The method “process” should be able to work with a container of objects allocated both “static” and “dynamic”…

template <typename T>
class Sample
{
public:
    T first;
    T second;
    typedef T Type;
};

template <typename Item> 
class Process
{
public:
    void process (Container <Item> *c) 
    {
        //Compile errors related to left part of the equation, see bellow, please
        typename Item::Type var = (*c)[0].first + (*c)[0].second; 

    }
};

The first option works but the second not

int main(int argc, _TCHAR* argv[])
{
Container <Sample <double> > c1;
Process <Sample <double> > a1;
a1.process(&c1);

//Dynamic allocation does not work  
Container <Sample <double> *> c2;
Process <Sample <double> *> a2;
a2.process(&c2);

}

How to design a class / method “process” so as to be able to work with a container of objects allocated both “static” and “dynamic” ? Thanks for your help..

Error   1   error C2825: 'Item': must be a class or namespace when followed by '::
Error   6   error C2228: left of '.second' must have class/struct/union
Error   5   error C2228: left of '.first' must have class/struct/union
Error   3   error C2146: syntax error : missing ';' before identifier 'var'
Error   4   error C2065: 'var' : undeclared identifier  
Error   2   error C2039: 'Type' : is not a member of '`global 
  • 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-21T02:06:18+00:00Added an answer on May 21, 2026 at 2:06 am

    Error 1 error C2825: ‘Item’: must be a class or namespace when followed by ‘::

    Here Item = ‘Sample *’ => This is a pointer, whatever what it target, pointer remain a plain old integer that contain an memory address, and has no attribute like Type.

    Something like that should do the trick

    template <typename T>
    struct traits {
        typedef typename T::Type Type;
    };
    
    template<typename T>
    struct traits<T*> {
        typedef typename traits<T>::Type Type;
    };
    
    template <typename Item> 
    class Process
    {
    public:
        void process (Container <Item>*c) 
        {
            typename traits<Item>::Type var;
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope it's the heat, this is the second question today and it's one
This is my second question on Bamboo ( My First One ). My understanding
This is my second question today and the first was an incredibly stupid question
It's my second ignorant question for today, this one even more ignorant than the
Is my second question on this topic today but on the previous one it
Today in my college a teacher asked me a question. He wrote this code
Okay this is a revised question from earlier today, I have included code to
(second question today - must be a bad day) I have a dataframe with
So, my second question based off of this application I'm teaching myself Objective C
Sorry for the second newbie question, I'm a developer not a sysadmin so this

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.