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>(i nt,double,double,char)"
(??0?$TryOMe@DHN@@QAE@HNND@Z) referenced in function _main 6 1409
B. Williams wrote:
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.
What exactly don't you understand? Your constructor doesn't exist,
essentially. You need to give it a BODY.
>
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 );
^^^^^^^^^^^^
Here you declare the constructor. Where is it *defined*?
>
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);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Here you *use* the constructor.
>
}
This is my error message.
TryOMe.obj : error LNK2019: unresolved external symbol "public:
^^^^^^^^^^^^^^^^^^^^^^^^^^
The linker needs to know where to find the constructor.
__thiscall
TryOMe<char,int,double>::TryOMe<char,int,double>(i nt,double,double,char)"
(??0?$TryOMe@DHN@@QAE@HNND@Z) referenced in function _main
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
B. Williams wrote:
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.
When template code produces mysterious error messages, try the same
thing without the templates. Make TryOMe an ordinary class, and replace
S, V, and R throughout it with ordinary types. I generally use int
unless there's a good reason for something else.
That's a hint: the problem has nothing to do with templates. They're
just a distraction here. Learn your tools, so that you understand basic
error messages (like the one you got) before you do advanced things like
writing templates. (Yes, I know, your instructor wants templates. That's
unfortunate. Too many people try to write templates too soon.)
--
-- Pete
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see www.petebecker.com/tr1book.
On Fri, 13 Oct 2006 17:26:25 -0400 in comp.lang.c++, "B. Williams" <wi*******@hotmail.comwrote,
>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.
This issue is covered in Marshall Cline's C++ FAQ. See the topic
"[10.6] Should my constructors use "initialization lists" or "assignment"?" It is always good to check the FAQ before posting.
You can get the FAQ at: http://www.parashift.com/c++-faq-lite/
B. Williams wrote:
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.
Your instructor gave you excellent feedback, the error message is
essentially saying that it sees a signature declaration but its unable
to resolve its implementation. Ignore that error at your own peril.
This is my error message.
TryOMe.obj : error LNK2019: unresolved external symbol "public: __thiscall
TryOMe<char,int,double>::TryOMe<char,int,double>(i nt,double,double,char)"
(??0?$TryOMe@DHN@@QAE@HNND@Z) referenced in function _main
Why don't you try a simple example and test the theory:
// --- A.h ---
#ifndef A_H_
#define A_H_
template< typename T >
class A
{
T t;
public:
A(T);
};
template< typename T >
A< T >::A(T val) : t(val)
{
}
#endif /* A_H_ */
// --- test.cpp ---
#include "A.h"
int main()
{
A<inta(99);
}
Now comment out the ctor implementation and try compiling. Note the
error.
That compiler is talking to you. Its helping you code. In fact: thats
its job.
Uncomment ctor's body... no error generated since its now got
implementation to execute.
Add a void get() const to the class declaration, try compiling - no
error generated !!!
What the hell? That, by the way, is a common way to disable a copy
ctor, for example.
ie: the compiler only generates an error if the call/invocation fails
to find a function body.
now add a call to get() in main().
int main
{
A<inta(99);
a.get();
}
try compiling again: error !!!
Its telling you exactly what is missing unambiguously. Right down to
the symbol involved.
On mine it says: test.cpp:19: undefined reference to `A<int>::get()
const
now define get() as follows:
template< typename T >
T A< T >::A::get() const
{
return t;
}
Will you recognise now that the compiler's output is actually VERY
useful?
Ignoring its output is like walking around blindfolded.
"Victor Bazarov" <v.********@comAcast.netwrote in message
news:eg**********@news.datemas.de...
B. Williams wrote:
>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.
What exactly don't you understand? Your constructor doesn't exist,
essentially. You need to give it a BODY.
>> 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 );
^^^^^^^^^^^^
Here you declare the constructor. Where is it *defined*?
>> 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);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Here you *use* the constructor.
>> }
This is my error message.
TryOMe.obj : error LNK2019: unresolved external symbol "public:
^^^^^^^^^^^^^^^^^^^^^^^^^^
The linker needs to know where to find the constructor.
>__thiscall TryOMe<char,int,double>::TryOMe<char,int,double>( int,double,double,char)"
(??0?$TryOMe@DHN@@QAE@HNND@Z) referenced in function _main
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I have attempted to define the constructor, but I'm not sure I'm doing it
correctly because of the multiple parameters. I have an example of defining
the constructor with just one parameter. This is my attempt. Is this even
remotely correct?
template< class R, class S, class V>
TryOMe< R, S, V >::TryOMe(S, V, V, R)
:s(var1), v1(var2), v2(var4), r(var3)
{
}
B. Williams wrote:
I have attempted to define the constructor, but I'm not sure I'm
doing it correctly because of the multiple parameters. I have an
example of defining the constructor with just one parameter. This is
my attempt. Is this even remotely correct?
template< class R, class S, class V>
TryOMe< R, S, V >::TryOMe(S, V, V, R)
>s(var1), v1(var2), v2(var4), r(var3)
{
}
Remotely, maybe. 'var1' through 'var4' are members, right? They
probably need to be _outside_ the parentheses in the initialiser
list. And you need to define 's', 'v1', 'v2', 'r'. Aren't those
_arguments_? How come your argument list doesn't have any real
arguments, only types?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: nanookfan |
last post by:
Hi all,
I'm having a bizarre problem converting XML files to HTML using an
XSLT. The problem is only occuring in my Netscape 7.0 browser. What
makes it more bizarre is that it is only...
|
by: Andy Fish |
last post by:
Hi,
I'm stuck with an XSL problem - can anyone give me any hints?
I have some XML with nested formatting tags like this:
<text>
this is plain
<bold>
this is bold
|
by: Clifford W. Racz |
last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML)
into xHTML? I have been trying to get the nested table code for my XSLT
to work for a while now, with no way to get the...
|
by: littlefitzer |
last post by:
Hi,
I have come across a tricky little problem, I hope maybe one of you
can help.
The problem I am having is that I need to parse two seperate values
from an XML document using XSL. The two...
|
by: C. Carbonera |
last post by:
/*
Hi,
I have a problem with explicit instantiation of templates in Visual
C++ 6.0.
I have provided the source below. I have an example of a function
template that produces incorrect output in...
|
by: Hendrik Schober |
last post by:
Hi,
I have a problem, that boils down to the following code:
#include <iostream>
#include <typeinfo>
class Test1 {};
class Test2 {};
class Test3 {};
|
by: Lionel B |
last post by:
Greetings.
The following code compiles ok and does what I'd expect it to do:
---------- START CODE ----------
// test.cpp
|
by: Prasad |
last post by:
HI,
I am a beginner in VC++..
I am trying to write a Win32 console application in visual studio..
I am using following header files..
#include <STRING>
using namespace std;
#include...
|
by: StephQ |
last post by:
First of all: distinction of keywords typename and class in template
arguments.
Accoarding to a post in a well known moderated group:
"There are three possibilities for template arguments:
1)...
|
by: pauldepstein |
last post by:
Let double NR( double x, double(*)(const double&) f ) be the
signature of a Newton-Raphson function NR.
Here, f is a function which returns a double and accepts a const
double&. The aim of...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |