1

i tried to create class object into another class with constructor, I got error that 'expected a type specifier'.I research example codes and I could not find anything wrong in my code. Error is into Cotp_connection.h file at LinkedList<uint8_t> list(0,NULL);

LinkedList.h

#include <cstdint>
#include <vector>
using namespace std;


template  <class T> class LinkedList
{
public:
    LinkedList() {};
    LinkedList(int size, LinkedList* next) :size(size), next(next) {};
    vector <T> data;
    int size;
    LinkedList* next;


};

Cotp_connection.h

#include "connect_tcp.h"
#include "LinkedList.h"


class Cotp_connection {
public:
    LinkedList <uint8_t> list(0,NULL); // Error is here


};
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Serhan Erkovan
  • 481
  • 4
  • 18
  • 3
    You can't do inline-initialization of members using parenthesis, as that could be parsed as function declarations. You need to use either "assignment" syntax or curly-braces `{}`. – Some programmer dude Oct 24 '19 at 08:00
  • 2
    Another solution is to make the `LinkedList` default constructor initialize the `size` and `next` members to the default values `0` and `nullptr` (respectively). – Some programmer dude Oct 24 '19 at 08:02
  • 1
    Or class Cotp_connection has an constructor and initialize it in the initializer list. – user1810087 Oct 24 '19 at 08:04
  • 1
    And lastly a general tip regarding linked lists: Think of them as lists of separate *nodes*. By using separate "list" and "node" structures (classes) many operations become much simpler, for example copying a list. Or even better: Don't implement your own list! Use [`std::list`](https://en.cppreference.com/w/cpp/container/list) (or [`std::forward_list`](https://en.cppreference.com/w/cpp/container/forward_list)) instead, if you even need a list to begin with ([`std::vector`](https://en.cppreference.com/w/cpp/container/vector) should always be the default "go to" container). – Some programmer dude Oct 24 '19 at 08:07
  • @Someprogrammerdude could you help me for another question ? – Serhan Erkovan Oct 24 '19 at 13:50
  • Don't change your question radically! If you have a new question then *post* another question. – Some programmer dude Oct 24 '19 at 15:27
  • @Someprogrammerdude sorry about that i have queation ban , it would not happened again – Serhan Erkovan Oct 24 '19 at 15:35

0 Answers0