Hello,
I'm completely newbie, I used pairs from <utylity>, but now I'm in need of something like "thirds", so I decided to create a template. I started with:

template <class T1, class T2, class T3> struct thirds
{
  typedef T1 first_type;
  typedef T2 second_type;
  typedef T3 third_type;

  T1 first;
  T2 second;
  T3 third;
  thirds() : first(T1()), second(T2()), third(T3()) {}

  thirds(const T1& x, const T2& y, const T3& z) : first(x), second(y), third(z) {}
  thirds <T1, T2, T3>  make_thirds(const T1& x, const T2& y, const T3& z)
  {
	  return ( thirds<T1,T2,T3>(x,y,z));
  }; 

  template <class U, class V, class F>
  thirds (const thirds<U,V,F> &p) : first(p.first), second(p.second), third(p.third) { }
	
};

And this seems to work, but when I am trying to do sth like:

thirds <int,int,int> trojka;

and than

trojka= thirds::make_thirds (1,2,3);

I got three errors:

1>.\main.cpp(43) : error C2955: 'thirds' : use of class template requires template argument list
1>        .\main.cpp(16) : see declaration of 'thirds'
1>.\main.cpp(43) : error C2955: 'thirds' : use of class template requires template argument list
1>        .\main.cpp(16) : see declaration of 'thirds'
1>.\main.cpp(43) : error C2352: 'thirds<T1,T2,T3>::make_thirds' : illegal call of non-static member function
1>        .\main.cpp(27) : see declaration of 'thirds<T1,T2,T3>::make_thirds'

Im using Visual Studio 2008.
Please give me an advice how to solve this problem.

Mike (:

Recommended Answers

All 3 Replies

Post the entire code so we can know where mistakes might have been made...

template <class T1, class T2, class T3> struct thirds
{
  typedef T1 first_type;
  typedef T2 second_type;
  typedef T3 third_type;

  T1 first;
  T2 second;
  T3 third;
  thirds() : first(T1()), second(T2()), third(T3()) {}

  thirds(const T1& x, const T2& y, const T3& z) : first(x), second(y), third(z) {}
  template <class U, class V, class F>
  thirds (const thirds<U,V,F> &p) : first(p.first), second(p.second), third(p.third) {}

  thirds<T1, T2, T3>  make_thirds(const T1 &x, const T2 &y, const T3 &z)
  {
	  return ( thirds<T1,T2,T3>(x,y,z));
  }; 
	
};

and

#include <iostream>
#include <utility>
#include <string>
#include "thirds.h"
using namespace std;

int main()
{	
	thirds <int,int,int> trojeczka1 (1,2,3);
        thirds <int,int,int> trojeczk2, trojeczka3;
	
trojeczka2 = make_thirds(2,4,6); //doesnot work
trojeczka3.make_thirds(5,6,7);  
cout << trojeczka3.first<< trojeczka3.second << trojeczka3.third ; //got all "0"
system("pause");
		return 0;
}

Make the make_thirds either a static function or a standalone function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.