Syntax error near unexpected token

When I try to execute my main function, I get the error "./main.cpp: line 6: syntax error near unexpected token `(' " I'm not sure what is wrong. Any help would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <fstream>
#include <iostream>
#include "Store.h"
#include "Product.h"

int main()
{
Store myStore("storedata");
myStore.print();

myStore.processOrders("orders.txt");
myStore.print();

return 0;
}
I think that it is a result of some invalid code in header "Product.h"
I tried removing the Product.h header and the Store.h header just to see if that would get rid of the error, but I still got the same error (except for line 4 instead of line 6).
You can not remove headers because the program uses names declared in these headers. You should look through "Product.h" Maybe you forgot to place a semicolon after some class definition.
Ok I put the headers back in and looked through my Product.h code, but I'm pretty sure it is ok. However, I just tried to compile my main.cpp code again and I got the following errors.

main.cpp:(.text+0x1b): undefined reference to `Store::Store(char const*)'
main.cpp:(.text+0x2a): undefined reference to `Store::print()'
main.cpp:(.text+0x3e): undefined reference to `Store::processOrders(char const*)'
main.cpp:(.text+0x4d): undefined reference to `Store::print()'
It means that these member functions are only declared in class Store but were not defined.
This is my Store.h code. Did I do something wrong in defining the functions?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef STORE_H
#define STORE_H

#include "Product.h"

//*****************************************************************
// FILE:      Store.h
// PURPOSE:   Contains the declaration for the Store class.
//*****************************************************************

class Store
   {
    private:

      // Data members

      Product productArray[30];
          int numOfProducts;

   public:

      // Method prototypes

          Store();
          Store(const char*);

          int getNumOfProducts();
          void sortProducts();
          int searchForProduct(char*);
          void processOrders(const char*);

          void print();
   };

#endif 
You should look through the module where these member functions are defined. Here in the header they are only declared.
Topic archived. No new replies allowed.