B
B. Williams
I have a problem dealing with class template where I was to write a class
and after submitting the class, this is the feedback I got back from the
instructor. I don't really understand it. Can someone please assist me.
Your constructor needs to do something. It should take in 4 values and pass
these to the individual set functions. I think if you go on to write main
you'll see the compiler errors and they should help.
I did write something for main, but the compiler errors left me with more
questions.
#ifndef TryOME
#define TryOME
template <class R, class S, class V>
class TryOMe{
public:
TryOMe(S s , V v1 , V v2 , R r );
void setvar1(S s) { var1 = s };
void setvar2(V v1) {var2 = v1};
void setvar4(V v2) {var4 = v3};
void setvar3(R r) { var3 = r};
S getvar1(){ return var1};
V getvar2(){ return var2};
V getvar4(){ return var4};
R getvar3(){ return var3};
private:
S var1;
V var2;
V var4;
R var3;
};
#endif
#include <iostream>
#include <string>
using std::endl;
using std::string;
#include "TryOMe.h"
int main()
{
TryOMe< char, int, double > test('can', 1, 48, 11.1);
}
This is my error message.
TryOMe.obj : error LNK2019: unresolved external symbol "public: __thiscall
TryOMe<char,int,double>::TryOMe<char,int,double>(int,double,double,char)"
(??0?$TryOMe@DHN@@QAE@HNND@Z) referenced in function _main
and after submitting the class, this is the feedback I got back from the
instructor. I don't really understand it. Can someone please assist me.
Your constructor needs to do something. It should take in 4 values and pass
these to the individual set functions. I think if you go on to write main
you'll see the compiler errors and they should help.
I did write something for main, but the compiler errors left me with more
questions.
#ifndef TryOME
#define TryOME
template <class R, class S, class V>
class TryOMe{
public:
TryOMe(S s , V v1 , V v2 , R r );
void setvar1(S s) { var1 = s };
void setvar2(V v1) {var2 = v1};
void setvar4(V v2) {var4 = v3};
void setvar3(R r) { var3 = r};
S getvar1(){ return var1};
V getvar2(){ return var2};
V getvar4(){ return var4};
R getvar3(){ return var3};
private:
S var1;
V var2;
V var4;
R var3;
};
#endif
#include <iostream>
#include <string>
using std::endl;
using std::string;
#include "TryOMe.h"
int main()
{
TryOMe< char, int, double > test('can', 1, 48, 11.1);
}
This is my error message.
TryOMe.obj : error LNK2019: unresolved external symbol "public: __thiscall
TryOMe<char,int,double>::TryOMe<char,int,double>(int,double,double,char)"
(??0?$TryOMe@DHN@@QAE@HNND@Z) referenced in function _main