LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   c++: "expected unqualified-id" newbie errors (https://www.linuxquestions.org/questions/programming-9/c-expected-unqualified-id-newbie-errors-579893/)

kpachopoulos 08-26-2007 04:02 AM

c++: "expected unqualified-id" newbie errors
 
This is FinancialProductsManager.cc:

Code:

#include "FinancialProductsManager.h"
#include <iostream>
#include <string>

using namespace std;

FinancialProductsManager::bool insertProduct(string fproduct, double value)
{
   
}

FinancialProductsManager::bool removeProduct(string fproduct)
{
   
}

int main(int argc, const char* argv[])
{   
    //cout << "testing the FinancialProductManager" << endl << "---------------------------------------------------";
   
}

and this is FinancialProductsManager.h:
Code:

#ifndef _FinancialProductsManager_H
#define        _FinancialProductsManager_H 

#include <hash_map.h>
#include <string>

using namespace std;


class FinancialProductsManager
{
   
    private:
        hash_map<string, int>  _financialProducts;
       
       
    public:
        bool insertProduct(string fproduct, double value);
        bool removeProduct(string fproduct);
}

#endif

When compiling with g++, i get
Code:

Running "rm -rf build/Debug/GNU-Generic/FinancialProductsManager.o" in /shared/kostas/10sem/programming/c++/arbigames


Clean successful. Exit value 0.

Running "make -f nbproject/Makefile-Debug.mk build/Debug/GNU-Generic/FinancialProductsManager.o" in /shared/kostas/10sem/programming/c++/arbigames

mkdir -p build/Debug/GNU-Generic
g++    -c -g -o build/Debug/GNU-Generic/FinancialProductsManager.o FinancialProductsManager.cc
In file included from /usr/include/c++/4.1.3/backward/hash_map.h:59,
                from FinancialProductsManager.h:4,
                from FinancialProductsManager.cc:1:
/usr/include/c++/4.1.3/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
In file included from FinancialProductsManager.cc:1:
FinancialProductsManager.h:22:7: warning: no newline at end of file
FinancialProductsManager.cc:5: error: expected unqualified-id before ‘using’
FinancialProductsManager.cc:7: error: expected unqualified-id before ‘bool’
FinancialProductsManager.cc:12: error: expected unqualified-id before ‘bool’
make: *** [build/Debug/GNU-Generic/FinancialProductsManager.o] Error 1

Build failed. Exit value 2.

What's the problem?

cupubboy 08-26-2007 04:16 AM

There are a few errors, I might miss some because I just woke up.

So let's see

First .. in your .h file you're missing a ';' (semicolon) after the class declaration (e.g.: class X { .... }; )

Also the way you define your methods is wrong, the right way is:

return_value ClassName::methodname(params) {}

so where you have
Code:

FinancialProductsManager::bool insertProduct(string fproduct, double value)
{
   
}

you should change to:
Code:

bool FinancialProductsManager::insertProduct(string fproduct, double value)
{
}

The same goes for FinancialProductsManager::removeProduct

On another note if you do "using namespace std" in the header file ... you don't need to do it also in the .cc files that include it

Hope this helps ...
Cheers!


All times are GMT -5. The time now is 01:42 PM.