c++ - Getting a "expected type-specifier" error when I instantiate a custom class in a custom class -


it seems error arises when don't include classes, after checking work seems in order...

for sake of brevity created test.h + test.cpp show how code breaking. reason when attempt instantiate class setaslist in test.cpp throws me title's error. commented line of code well

thank insight!

main:

#include <iostream> #include "test.h" using namespace std;  int main(int argc, char **argv) {  } 

test.h

#ifndef _test #define _test  #include "setasoc.h" #include "setaslist.h" using namespace std; class test { public:     test(){};     void example();  }; #endif 

test.cpp:

#include "test.h"  void test::example() {     setaslist *trial = new setaslist::setaslist(); // <-- test.cpp:6:25: error: expected type-specifier } 

setaslist.h

#ifndef _setlist #define _setlist  #include <iostream> #include <stdlib.h> #include "set.h" using namespace std;  //node dll typedef struct node{ node *previous; node *next; int value; } node;  class setaslist: set {  private:     node *head;     node *tail;     int count;  public:       ~setaslist();     //method=0 pure virtual method abstract classes     int size();     setaslist();     int& operator[](const int& index);     void add(int value);     void removeobject(int value);     void removeat(int index);     int indexof(int value);     void remove(node *obj); //removes node };  #endif 

setaslist.cpp

#include "setaslist.h"  int setaslist::size() { return count; }  setaslist::setaslist() {     head = null;     tail = null;     count =0; }  setaslist::~setaslist() {     node *temp = head;     node *freenode;     for(int a=0; a< count; a++)     {          freenode = temp;         temp = temp->next;         delete freenode;     }     head = null;     tail = null;     count =0; }  int& setaslist::operator[](const int& index) {     node *temp = head;      for(int a=0; a< count; a++)     {          if(index == a)             return temp->value;         temp = temp->next;     }     throw 321; }  void setaslist::add(int value) {     node *newnode = new node();     newnode->value = value;     if(count ==0)     {         head= newnode;         tail = newnode;     }     else     {         tail->next = newnode;         newnode->previous = tail;         tail = newnode;     }      count ++;  }  void setaslist::removeat(int index) {     node *temp = head;      for(int a=0; a< count; a++)     {          if(index == a)             {              return;             }             temp = temp->next;     } }  void setaslist::removeobject(int value) {     node *temp = head;      for(int a=0; a< count; a++)     {          if(value == temp->value)         {         remove(temp);         return;         }         temp = temp->next;     } }  int setaslist::indexof(int value) {     node *temp = head;     for(int a=0; a< count; a++)     {          if(temp->value == value)         {         return a;         }         temp = temp->next;     }     return -1; }  void setaslist::remove(node *obj) {      if(count ==1)     {   delete head;         head = null;         tail = null;     }     else     {         node *prev = obj->previous;         node *next = obj->next;         prev->next = next;         next->previous = prev;         delete obj;     }     count--; } 

as error message said, setaslist::setaslist not type-specifier, change

setaslist *trial = new setaslist::setaslist(); 

to

setaslist *trial = new setaslist(); 

the default constructor called, don't need specify it.


Comments

Popular posts from this blog

javascript - Wordpress slider, not displayed 100% width -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -