• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ problem w/ Visual C++

agnitrate

Diamond Member
Ok, something is wrong with this. I've stared at this for about 20 minutes and I can't fix it! This is either an incredibly simple mistake or something is horribly wrong with MS VC++ .NET I've never used .net before but my professor is making us use it, so I'm struggling to get through this.

Compiler gives this lovely error : 'getString' : is not a member of 'TreeTokenReader'

Here are the important parts of main.cpp

#include <iostream>
#include "ParseInput.h"
#include "TreeSequence.h"
#include <string.h>

using namespace std;

int main(int argc, char* argv[])
{
TreeTokenReader input;
char filename[256];

cout << "Please enter the filename you wish to scan" << endl;
cin >> filename;
if( input.openFile(filename) != 1 ) {
return 1; // file doesn't exist, don't go further
}
input.getString();
return 0;
}


As you can see, getString() is at the bottom part.

Here's the .h :

class TreeTokenReader {
protected:
char fileName[256];
ifstream *inpt;

public:
enum return_type { MYEOF = 0, LEFT_PAREN, RIGHT_PAREN, INTEGER, UNKNOWN }; // possible tokens
int value; // for integer token the value of the integer

TreeTokenReader();
~TreeTokenReader();

void getString();
....blah...blah

};


Here's the .cpp

// called only when the file exists
void TreeTokenReader::getString() {
....blah...blah....
}


What the hell is wrong with this?! It works for all of the other functions! I don't like you Visual C++!! I want my vi back!

-silver
 
nope 🙁

That's the only error. This is just the beginning of my project and this is so trivial. This is basic class accessing.

-silver
 
Did you remember to include the .h file in your .cpp file where the class definition is? Dunno if it matters or not, but I've always done declarations public, protected, and private in that order.
 
Yup, it reads the original functions given by my professor. Do I have to 'register' a function with visual c++?

I just tried a test function where I made it return void and only print text to the screen. It wouldn't work.

The .h is there and working fine. I am pretty sure it's not syntax.

-silver
 
Originally posted by: agnitrate
Yup, it reads the original functions given by my professor. Do I have to 'register' a function with visual c++?

I just tried a test function where I made it return void and only print text to the screen. It wouldn't work.

The .h is there and working fine. I am pretty sure it's not syntax.

-silver

no you dont have to register functions with it or anything like that.
 
Originally posted by: Ameesh
can we get the exact compiler error?

error C2039 : 'getString' : is not a member of 'TreeTokenReader'

That's all it gives me. I checked .NET site citing an example of an improperly typed function name, but that's not the case here.

I got the .h and .cpp from my professor for the project and all his functions work. Any functions I try to declare, don't work. I think I'm doing something with VC++ wrong. It shows the functions there under the class and auto-completes when I type them, but just doesn't work.

-silver
 
getString might be a function of string.h
so you might wanna try renaming it everywhere... your .h and .cpp files.
just a guess... dont know if getString is really a part of string.h but it could be. no harm in trying i guess.
 
TreeTokenReader doesn't have the function getString(), and from what you're doing, it looks like you're calling it as a member function of input, which is of type TreeTokenReader.

Isn't there another way to use getString() and get the returning value to store into "input"?

If i'm not making sense, I apologize. I get C++ and Java confused easily. =/ Not to mention I haven't touched it in a year.
 
getString might be a function of string.h
so you might wanna try renaming it everywhere... your .h and .cpp files.
just a guess... dont know if getString is really a part of string.h but it could be. no harm in trying i guess.

I just tried renaming a function 'test' and it gave me the same error 🙁

TreeTokenReader doesn't have the function getString(), and from what you're doing, it looks like you're calling it as a member function of input, which is of type TreeTokenReader.

Isn't there another way to use getString() and get the returning value to store into "input"?

input is of type TreeTokenReader which has a public function getString() unless I coded something incorrectly. I just need a function to perform a certain number of steps within the class. It doesn't matter what the name is to me.

Is there a difference between #include<iostream> and #include<iostream.h>?

Nope, just newer compilers want <iostream> instead of .h and cite it as deprecated. I'm doing this in .NET and transporting to VC++ 6 since that's what it has to be compatible with. But VC++ 6 locks every time I get a compiler error, but that's another thread...

Folks in Software might be able to help...

I checked and only saw questions about software, not coding. My bad.

-silver
 
hmm... all i can think of is that its not linking your .cpp file correctly to the class.

did you do the
ifndef then define blah
stuff. it helped me solve problems like this before.
 
Originally posted by: Ameesh
is the Token Tree Reader in its own namespace?

Nope, just it's own class. Oddly, my professor decided to name the file InputParser.h/.cpp. I'm not sure if that would have an effect, however.

Yup, johnjbruin, did all the #ifndef stuff. It's only included once though so it shouldn't make a big deal.

-silver
 
Originally posted by: agnitrate
Originally posted by: Ameesh
is the Token Tree Reader in its own namespace?

Nope, just it's own class. Oddly, my professor decided to name the file InputParser.h/.cpp. I'm not sure if that would have an effect, however.

Yup, johnjbruin, did all the #ifndef stuff. It's only included once though so it shouldn't make a big deal.

-silver

the reason i asked is that msdn has some explanation of the error

C2039
 
It works. I changed nothing. Closed/reloaded VC++ .NET. Who knows what happened.

Now on to the meat of the project 🙂 Thanks for the help everyone, epsecially Ameesh.

-silver
 
Back
Top