Home Passing an instance of a user defined template class to a non templated function
Reply: 0

Passing an instance of a user defined template class to a non templated function

user922
1#
user922 Published in April 24, 2018, 8:35 am

I have following implementation:

#include <cstddef>

template<typename Data, size_t Size> 
class Demo
{  
public:
    Demo();

private:
    Data data[Size];
};

void f(Demo<int, size_t>& demoObj)
{

}


int main()
{
    Demo<int, 100> demoObj;

}

I get the following error when I compile:

g++ -std=c++11 temp.cpp
temp.cpp:13:24: error: type/value mismatch at argument 2 in template parameter list for ‘template<class Data, long unsigned int Size> class Demo’
 void f(Demo<int, size_t>& demoObj)
                        ^
temp.cpp:13:24: note:   expected a constant of type ‘long unsigned int’, got ‘size_t {aka long unsigned int}’

The error is not making sense to me. Please help me understand it. Also, how do I pass demoObj to function f? I mean how o write the definition of f.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.343797 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO