Constructor with two parameters

I have the following class and I don't know how to initialize it my constructor with the private variables.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
template<typename U, size_t N>
class Bar
{
public:
Bar();
Bar(char bad, int num);

private:
const size_t pac_;
U * dat_;
size_t siz_;
char bad_;
int num_;
}


This is how I tried to initialize it. I don't know if it is right though.

1
2
3
4
5
template<typename U, size_t N>
Bar<U, N>::Bar(char bad, int num_) : pac_(N), dat_(), size(0);
{

}


Can someone explain how to initialize this. The amount of private variables to parameters is confusing me.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
template < typename U, size_t N >
class Bar
{
    public:

        // initialise all members with their default intialisers
        Bar() = default ;

        // initialise bad_ with bad, num_ with num,
        // initialise all other members with their default intialisers
        Bar( char bad, int num ) : bad_(bad), num_(num) {}

    private:

        const size_t pac_ = N ; // superfluous (we can just use N instead)

        U* dat_ = nullptr ; // strongly consider using std::vector instead
        size_t siz_ = 0 ; // not required if vector is used (vector knows its own size)

        char bad_ = 'A' ;
        int num_ = 0 ;
};

https://rextester.com/VKC80518
Topic archived. No new replies allowed.