Re: Chapter 12 problems

88 views
Skip to first unread message

tfmccarthy_verizon_mail

unread,
May 3, 2012, 2:33:20 PM5/3/12
to ppp-p...@googlegroups.com
In checking my notes I see there is a problem in the header the Vector_ref
template.

template<class T>
class Vector_ref
{
//...
private: // prevent copying
Vector_ref(const Vector&); // error: 'Vector' : use of class template
requires template argument list
Vector_ref& operator=(const vector&); // error: 'Vector' : use of class
template requires template argument list
};

This deals with template specification which is covered later on I think.

These declarations are no used and are there simply to prevent anyone
(programmer or compiler) from copying a Vector_ref object.

The fix for this is to comment out the two delcarations and add the
replacements,

template<class T>
class Vector_ref
{
//...
private: // prevent copying
//Vector_ref(const Vector&); // error: 'Vector' : use of class template
requires template argument list
//Vector_ref& operator=(const vector&);
Vector_ref(const Vector_ref<T>&);
Vector_ref& operator=(const Vector_ref<T>&);
}

The change here is to use the template declaration for Vector_ref rather
than Vector. I think there are two errors here:

1. A typo of "Vector" rather than "Vector_ref"
2. Not using the template declaration Vector_ref<T>

----- Original Message -----
From: "Arsen Babakhanyan" <arse...@gmail.com>
To: "PPP-public" <ppp-p...@googlegroups.com>
Sent: Thursday, May 03, 2012 10:47 AM
Subject: Chapter 12 problems


> My dear friends i see that this problem had a lot of people,
> but i hadnt found any solutions for me
> On Visual Studio 2010 i cant compile first example from chapter 12
> here was problem with :Circle(Point p, int rr) in Graph.cpp
> i commented it out and now my problem changes
> it says
> error C2872: 'Polygon' : ambiguous symbol
> but without polygon every thing else works
> i tested other samples from book
> samples with Rectangle doesnt work too, with same report
> please help me i was looking for solution all this day


tfmccarthy_verizon_mail

unread,
May 3, 2012, 2:50:04 PM5/3/12
to ppp-p...@googlegroups.com
Ah! Even then an error.

The correct declaration for the Vector_ref assignment operator is,

Vector_ref<T>& operator=(const Vector_ref<T>&);

The assignment operator returns a reference to the object. Since the object
here is a template class, it must be specified as accepting a template
object reference and returning a template object.
Reply all
Reply to author
Forward
0 new messages