Search:
Forum
General C++ Programming
My vector class isn't working when i cre
My vector class isn't working when i create objects
Feb 21, 2018 at 11:17pm UTC
joshgarza
(21)
Whenever I try to create an object I get this error:
"Implicit instantiation of undefined template 'std::__1::vector<int, std::__1::allocator<int> >'"
Here is the main file, I've commented where the error occurs.
https://pastebin.com/tSHPFzVe
Here is the header file with the class.
https://pastebin.com/1SRUMChZ
Feb 21, 2018 at 11:45pm UTC
Peter87
(11237)
Your vector class template is named myVector so you need to use that name when creating the objects.
1
2
myVector<
int
> myvecA; myVector<
int
> myvecB(10);
Feb 21, 2018 at 11:55pm UTC
joshgarza
(21)
Okay, I did that and it led to a whole host of new errors. Whenever I call the object in the program it now gives me the error "Type 'myVector<int>' does not provide a subscript operator"
Feb 22, 2018 at 12:04am UTC
keskiverto
(10402)
What is supposed to happen, if I write:
myvecB [ 7 ] = 42;
Your (template) class does not have
operator
[](size_t)
, does it?
Feb 22, 2018 at 12:16am UTC
joshgarza
(21)
Oh no it doesn't, I didn't realize it needed an overload operator. Thank you m'lord.
Topic archived. No new replies allowed.
C++
Information
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs