GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Nov-2003, 16:37
RealmMaster RealmMaster is offline
Awaiting Email Confirmation
 
Join Date: Nov 2003
Posts: 3
RealmMaster is an unknown quantity at this point

Microsoft Visual C++6.0 - Illegal use of this type as an expression


Hey everyone, I am new here, but this is driving me nuts. Heh. I am doing this project for my Computer Science class, and am trying to complie this in Microsoft Visual C++ 6.0, but get the following error:

d:\compsci2\project5binarytree\driver.cpp(65) : error C2275: 'WordBST' : illegal use of this type as an expression

d:\compsci2\project5binarytree\driver.cpp(44) : see declaration of 'WordBST'

Error executing cl.exe.


Here is the code for my driver file, and I've marked the line thats giving the error with a comment, at the very bottom of the code.
(Line that starts - BST<Word>*getWord ).

Thanks in advance.

CPP / C++ / C Code:
#include <iostream>
#include "bst.h"
#include "binaryWords.h"
#include <fstream>
#include<cstring>
#include<cassert>

using namespace::std;

//traversal
void inOrderTraversal(BST<Word>* v)
{
	if (!v->isEmpty())
	{
		inOrderTraversal(v->left());
		cout<<v->getData() << '\t';
		inOrderTraversal(v->right());
	}
}




void main(void)
{
// typedef is common approach to code simplification
// lets one think about an integer BSt and integer BST pointer rather than the more complex syntax
 
Word v[200];


ifstream ifile("treetext.txt") ;
   assert(ifile) ;


   for(int wcount = 0 ; !ifile.eof() ; wcount++)
      ifile >> v[wcount] ;

// print output of all ints - correct count for 1 too many
   for(int i = 0 ; i < wcount - 1 ; i++)
      cout << v[i]<<" ";
   cout << endl << endl ;   // spacer

typedef    BST<Word>   WordBST ;
typedef    WordBST *    WordBSTPtr ;
 
WordBSTPtr   b(new WordBST) ;       // create a BST to receive data
 

cout<<"We are now loading the tree and traversing it to make sure its loaded: "<<endl;

for(int x=0; x<wcount; x++)
{
	b->Insert(v[x]);
}

cout << endl;
inOrderTraversal(b);
cout << endl;


Word Test("seeing");
cout<<"Testing the first word"<< Test.getText()<<endl;
// Question : is seeing in the tree ?
BST<Word>*getWord = WordBST.retrieve(Test);  // Error  C2275 is located here
   
   if(getWord->isEmpty( ))
     cout << " seeing NOT FOUND" << endl ;
   else
      cout << " seeing FOUND" << endl ;
}
  #2  
Old 16-Nov-2003, 18:40
RealmMaster RealmMaster is offline
Awaiting Email Confirmation
 
Join Date: Nov 2003
Posts: 3
RealmMaster is an unknown quantity at this point
Ah, my friend got it, nevermind then. Ah well...
  #3  
Old 17-Nov-2003, 05:26
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Hello RealmMaster,

I am sorry no one could get to your issue in time, but I appreciate that you came back to say that you found the solution.

Since this thread may start appearing in the Search Engine results for a similar phrase search, could you possibly post the solution so readers will find some value in the information you provide here?
  #4  
Old 05-Dec-2003, 18:19
RealmMaster RealmMaster is offline
Awaiting Email Confirmation
 
Join Date: Nov 2003
Posts: 3
RealmMaster is an unknown quantity at this point
Hey, it's okay. Sorry for the long reply as well.

Here is what we changed:

CPP / C++ / C Code:
Word Test("seeing");
cout<<"Testing the first word "<< Test.getText()<<endl;
// Question : is seeing in the tree ?
WordBSTPtr getWord(b->retrieve(Test));
   
   if(getWord->isEmpty( ))
     cout << " seeing NOT FOUND" << endl ;
   else
      cout << " seeing FOUND" << endl ;

Hopefully anyone else with this problem this will help
  #5  
Old 07-Apr-2006, 00:47
vivid vivid is offline
New Member
 
Join Date: Apr 2006
Posts: 1
vivid is on a distinguished road

Re: Microsft Visual C++6.0 - Illegal use of this type as an expression


Missed three hours of productive work because one character.
I had code like this:

CPP / C++ / C Code:
function() {
  // actions
  if (!something()) {
      goto cleanup;
  if (!something_else())
      goto cleanup;
  // and so on
cleanup:
  // do some cleanup
}

So the '{' character in wrong place gave me an error C2275: 'some typedef' : illegal use of this type as an expression. The error was much further down the code than the actual cause of error and I was puzzled. Well finally I found the reason of this very odd error message. Hope this helps someone and saves valuable time and nerves.
Last edited by admin : 07-Apr-2006 at 01:01. Reason: Please insert your C code between [c] & [/c] tags
  #6  
Old 24-Aug-2006, 13:51
rogerpack rogerpack is offline
New Member
 
Join Date: Aug 2006
Posts: 1
rogerpack is on a distinguished road
Talking

Re: Microsoft Visual C++6.0 - Illegal use of this type as an expression


Or if you're like me you may have said
XalanDOMString str = testFunction(XalanDOMString)

notice the use of XalanDOMString (the type) in place of the parameter. My bad :-)
 
 

Recent GIDBlogMeeting the populace by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:20.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.