#Template initialization

23 messages · Page 1 of 1 (latest)

foggy harness
#

i create a template class with a constructor but don't know why i get this error

datalib.cpp: In function ‘int main()’:
datalib.cpp:260:20: error: invalid conversion from ‘Queue<int>*’ to ‘int’ [-fpermissive]
  260 | Queue<int> queue = new Queue<int>(200);
      |                    ^~~~~~~~~~~~~~~~~~~
      |                    |
      |                    Queue<int>*
datalib.cpp:208:11: note:   initializing argument 1 of ‘Queue<T>::Queue(int) [with T = int]’
  208 | Queue(int capacity){
      |       ~~~~^~~~~~~~

amber tigerBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

hidden bone
#

new returns a pointer

#

but why are you using dynamic memory aka new?

supple jetty
#

I think he is trying to allocate Queue size

hidden bone
#

should be irrelevant, the Queue should handle that internally

#

here the Queue object itself is being made dynamically, when there's likely no reason for it to be

supple jetty
#

yeah but that's most likely what he was trying to do 😅

candid cedar
#

Queue<int> queue(200);

foggy harness
supple jetty
foggy harness
#

give me a sec

supple jetty
#

Or just send it here actually. Just make sure there is no template right before int main(){...

foggy harness
#

there is a templeate since my teacher doesn't allow us to use libraries

supple jetty
#
template<...> // you need to delete this line
int main() {
    // ...
}
foggy harness
#

why?

#

before main is just a };

#

from a class

supple jetty
#

Hmm

#

You should send the code so we can see what is going on though.

supple jetty
#

Did you forget a semicolon somewhere? lol

amber tigerBOT
#

@foggy harness

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

#

@foggy harness

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.