constructor - C++ unexpected syntax errors -
ok have updated code:
#ifndef vector_h #define vector_h #include<cstdlib> #include<vector> #include<iostream> using namespace std; template < typename t> class myclass { public: myclass() : size(10), index(0) { vec = new t[10]; }; myclass(int i) : size(i), index(0) { vec = new t[i]; }; friend bool add(t i); virtual ~myclass(); friend ostream& operator<<(ostream& out, const t& obj); private: t * vec; int size; int index; }; template <typename t> virtual myclass<t>::~myclass() { delete[] vec; } template <typename t> ostream& operator<<(ostream& out, const myclass<t>& obj){ (int = 0; < index; ++i) out << obj[i] << " "; out << endl; } template <typename t> bool myclass<t>::add(t i){ if (size == index){ size *= 2; realloc(vec, size); } vec[index++] = i; } #endif // !vector_h
error list: error 1 error c2039: 'add' : not member of 'myclass' c:\users\mihaibogdan\documents\visual studio 2013\projects\dashit\dashit\header.h 41
you should use qualified names
friend std::ostream& operator<<( std::ostream& out, const t& obj);
standard c++ names declared in name space std
.
otherwise compiler looks unqualified name ostream
in global name space not of course declared.
Comments
Post a Comment