Sign in to follow this  
OpenGL_Guru

enumerated types in classes = trouble?

Recommended Posts

OpenGL_Guru    104
here is the class i am trying to call from, followed by my call from main and then the error message that i am getting.. is there something i should do? i dont see it... ive never had to deal with enumerated types before in all my years of C++, never really needed to use it.. anyway i appreciate your time! thanks! class
class NcFile
{
  public:

    virtual ~NcFile( void );

    enum FileMode 
	  {
	   ReadOnly,	// file exists, open read-only
	   Write,		// file exists, open for writing
           Replace,	// create new file, even if already exists
	   New		// create new file, fail if already exists
          };

    NcFile( const char * path, FileMode = ReadOnly);// ,
	   // size_t *chunksizeptr = NULL, // optional tuning parameters
	    //size_t initialsize = 0 );

    NcBool is_valid( void ) const;         // opened OK in ctr, still valid
......
} 
from main.cpp
//netcdf reader for use with the GDEM Software...
#include <iostream>
#include <sstream>
#include "netcdfcpp.h"

using namespace std;

int main()
{

 NcFile *a = new NcFile("sspgdemv3s01.nc", NcFile::FileMode = ReadOnly);
 
 return 0;
}
error(s): --------------------Configuration: netcdf_test - Win32 Debug-------------------- Compiling... main.cpp C:\Program Files\Microsoft Visual Studio\VC98\MyProjects\netcdf_test\main.cpp(11) : error C2065: 'ReadOnly' : undeclared identifier C:\Program Files\Microsoft Visual Studio\VC98\MyProjects\netcdf_test\main.cpp(11) : error C2275: 'NcFile::FileMode' : illegal use of this type as an expression Error executing cl.exe. netcdf_test.exe - 2 error(s), 0 warning(s)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Hi.

Replace the line
NcFile *a = new NcFile("sspgdemv3s01.nc", NcFile::FileMode = ReadOnly);
by this:
NcFile *a = new NcFile("sspgdemv3s01.nc", NcFile::ReadOnly);
This should do the job.

Ghyslain Abel

Share this post


Link to post
Share on other sites
OpenGL_Guru    104
ok i changed the code to what you said, which i have tried before...and this is what i get back from the compiler... WTF??? i am using Visual C++ 6. just if you are wondering... thanks again...

--------------------Configuration: netcdf_test - Win32 Debug--------------------
Compiling...
main.cpp
Linking...
main.obj : error LNK2001: unresolved external symbol "public: __thiscall NcFile::NcFile(char const *,enum NcFile::FileMode)" (??0NcFile@@QAE@PBDW4FileMode@0@@Z)
Debug/netcdf_test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

netcdf_test.exe - 2 error(s), 0 warning(s)

Share this post


Link to post
Share on other sites
Ghyslain    122
Hi again.

You must define the constructor:

NcFile::NcFile( const char * path, FileMode ReadOnly )
{
//...
}

The error message said that this function was declared but not defined.

Ghyslain Abel

Share this post


Link to post
Share on other sites
Conner McCloud    1135
Quote:
Original post by OpenGL_Guru
ok i changed the code to what you said, which i have tried before...and this is what i get back from the compiler... WTF??? i am using Visual C++ 6. just if you are wondering... thanks again...

--------------------Configuration: netcdf_test - Win32 Debug--------------------
Compiling...
main.cpp
Linking...
main.obj : error LNK2001: unresolved external symbol "public: __thiscall NcFile::NcFile(char const *,enum NcFile::FileMode)" (??0NcFile@@QAE@PBDW4FileMode@0@@Z)
Debug/netcdf_test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

netcdf_test.exe - 2 error(s), 0 warning(s)

Your linker can't find the NcFile constructor. Have you written a body for it yet? If so, is it included in your project? Perhaps it isn't properly named:

//in your source file
NcFile(char const*, NcFile::FileMode) {
...
}
//rather than
NcFile::NcFile(char const*, NcFile::FileMode) {
...
}

CM

Share this post


Link to post
Share on other sites
OpenGL_Guru    104
well the thing is is i didnt write this code.. i am working on reading in binary data and such through Netcdf format. it was originally a C version but now there is a C++ now and it only comes with a header file that references some old files from the C version. its a lot to read but it might explain better what is happening.

in essence all i have is a .h file but not the implementation of it, which i think is indirectly calling the C style functions from the C version instead of making the user do all the un-necessary calls.


can anyone help?

Share this post


Link to post
Share on other sites
SirLuthor    364
You need the function definitions, either in the form of the source code, or as a library to link with your project, or else that stuff is not going to compile.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this