Hello,

I have come across a compile error, which should have a very simple solution, but I cannot figure it out. I am fairly new to programming and am still getting used to OOP.

I am trying to call a function from another class. The class seems to work but I get the following errors:

1>c:\documents and settings\abrounstein\my documents\visual studio 2008\projects\roboextract\roboextract\main.cpp(12) : error C2653: 'RoboExtract' : is not a class or namespace name
1>c:\documents and settings\abrounstein\my documents\visual studio 2008\projects\roboextract\roboextract\main.cpp(12) : error C3861: 'askUser': identifier not found

Other people seem to have this error, but it is because they forgot to include the header file into the .cpp file calling the class function, but I definetly have it included.

FYI: I am programming with the Qt toolkit

main.cpp is:

#include "RoboExtract.h"
#include <QApplication>
#include <QTextStream>
#include <iostream>
#include <QDir>

using namespace std;

 int main(int argc, char *argv[])
 {
	QApplication app(argc, argv);
	RoboExtract::askUser();
    return app.exec();
 }

The RoboExtract.h is:

#ifndef ROBOSEARCH_H
#define ROBOSEARCH_H
#include <QDir>
#include "RoboExtract.h"

class RoboExtract 
{
public:
	RoboExtract(void);
	bool readFiles(QDir directory, QString parameter);
	bool askUser();
	~RoboExtract(void);
};

#endif

The relevent code for RoboExtract.cpp is:

#include "RoboExtract.h"
#include <QApplication>
#include <QTextStream>
#include <iostream>
#include <QDir>
using namespace std;

...

bool RoboExtract::readFiles(QDir directory, QString parameter)
{
	return true;
}

bool RoboExtract::askUser()
{

	...

	return readFiles(directory, parameter);

}

.... I've tried everything I could think of, I just don't have quite enough experience to figure out what to try next.

Any suggestions would be greatly appriciated! Thanks!!!

Haha, because I was being silly. I have taken it out, and I get the same compile errors.

Yes, sorry I had that originally, but I took it out for some reason. This is what I had in RoboExtract.h:

class RoboExtract 
{
public:
	RoboExtract(void);
	static bool readFiles(QDir directory, QString parameter);
	static bool askUser();
	~RoboExtract(void);
};

I get the exact same error

Well apparently you haven't posted the code that has the problem. No point in me looking at something that isn't current code. So, unless you post CURRENT code I'm not going to bother looking at it any more.

Well, now I'm not sure what to post, because that is my current code.

There is a Qt generated source file, which I'll add below, but I don't see how it's related to this error.

/****************************************************************************
** Meta object code from reading C++ file 'RoboExtract.h'
**
** Created: Wed Aug 13 14:59:06 2008
**      by: The Qt Meta Object Compiler version 59 (Qt 4.4.1)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/

#include "../RoboExtract.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'RoboExtract.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 59
#error "This file was generated using the moc from 4.4.1. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif

QT_BEGIN_MOC_NAMESPACE
static const uint qt_meta_data_TestDialogDlg[] = {

 // content:
       1,       // revision
       0,       // classname
       0,    0, // classinfo
       1,   10, // methods
       0,    0, // properties
       0,    0, // enums/sets

 // signals: signature, parameters, type, tag, flags
      15,   14,   14,   14, 0x05,

       0        // eod
};

static const char qt_meta_stringdata_TestDialogDlg[] = {
    "TestDialogDlg\0\0eep()\0"
};

const QMetaObject TestDialogDlg::staticMetaObject = {
    { &QDialog::staticMetaObject, qt_meta_stringdata_TestDialogDlg,
      qt_meta_data_TestDialogDlg, 0 }
};

const QMetaObject *TestDialogDlg::metaObject() const
{
    return &staticMetaObject;
}

void *TestDialogDlg::qt_metacast(const char *_clname)
{
    if (!_clname) return 0;
    if (!strcmp(_clname, qt_meta_stringdata_TestDialogDlg))
        return static_cast<void*>(const_cast< TestDialogDlg*>(this));
    if (!strcmp(_clname, "Ui_TestDialog"))
        return static_cast< Ui_TestDialog*>(const_cast< TestDialogDlg*>(this));
    return QDialog::qt_metacast(_clname);
}

int TestDialogDlg::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: eep(); break;
        }
        _id -= 1;
    }
    return _id;
}

// SIGNAL 0
void TestDialogDlg::eep()
{
    QMetaObject::activate(this, &staticMetaObject, 0, 0);
}
QT_END_MOC_NAMESPACE

As I suspected, it wasn't a problem with the code, it was setup in correctly in Visual Studio. It seems to be working now. Thanks for your help

What I had done was taken an old project of mine, to get the basic setup. This worked well, until I added a source and header file. It overwrote the header files that I had included in the project, but showed the new header files that were correct. Basically it was reading an old file, but it was showing a new one, and I didn't realize it until I tried opening it in a new program. So, it was basically user error.

may be you have more than one files have
#ifndef ROBOSEARCH_H
#define ROBOSEARCH_H
#endif

Comments
Don't bump old threads

there could be a possibility of this error if the header file is included before the #include "stdafx.h" in cpp file. include the header file after #include "stdafx.h". For ex :
//Below would throw C2653
#include "yourdeclarion.h"
#include "stdafx.h"

//Below would compile properly
#include "stdafx.h"
#include "yourdeclarion.h"

This article has been dead for over six months. Start a new discussion instead.