Jump to content

Проблема с шаблонами в С++


Recommended Posts

Объясните, пож, почему возникают ошибки и помогите исправить:

"error: expected ';' before 'p'"

"error: 'p' was not declared in this scope"

"error: dependent-name 'std::vector::const_iterator' is parsed as a non-type, but instantiation yields a type"

#ifndef ASSOC_H_#define ASSOC_H_#include <iostream>#include <string>#include <vector>#include <iterator>using std::vector;using std::string;using std::cout;template<class T>class Assoc{   private:       struct Pair       {           T name;           double val;           Pair(T n = "", double v = 0):name(n),val(v){}       };       vector<Pair> vec;   public:       Assoc(){}       void print_all() const;};template<class T>void Assoc<T>::print_all() const{   for (vector<Pair>::const_iterator p = vec.begin(); p != vec.end(); p++)       cout << p->name << ": " << p->val << '\n';}#endif
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...