Thread: getting an error I can't figure out....

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    getting an error I can't figure out....

    I was wondering if someone could help I am getting these error message and I can't figure out how to fix them any ideas??

    error C2228: left of '.string' must have class/struct/union type
    C:\Documents and Settings\Owner\My Documents\Computer error C2664: 'lin_search' : cannot convert parameter 1 from 'class index [2000]' to 'class index *[]'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    here is my code
    Code:
    class index{
    	public:
    		int number;
    		char string[100];
    		char url[50];
    };
    
    bool lin_search(index *l[], char word[]){
    	for(int i = 0; i <= 20; i++) 
    		if(l[i].string == word)
    			return true;
    	
    	return false;
    }
    I call the function like this:

    Code:
    	index w[2000];
    	char word[100];
    	int count = 0;
    	ifstream filein("collection.txt", ios::nocreate);
    
    				while(!addrin.eof()){
    					addrin >> word;
    					if(lin_search(w, word) == true){}
    I hope someone can help. Thanks

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >>bool lin_search(index *l[], char word[]){

    Should be:

    bool lin_search(index l[], char word[]){
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    7
    I gave that a try but it wasn't passing the class object through the function I couldn't check if the strings were the same.

  4. #4
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    I believe your problem is that l[i] is a pointer, so you need to write your if statement like so:
    Code:
             if(l[i]->string == word)
                 return true;
    At least thats what the error is complaining about.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3 dimensional figure volume
    By thekautz in forum C++ Programming
    Replies: 2
    Last Post: 01-20-2009, 05:22 PM
  2. trying to figure out someone's code for a plugin
    By paulpars in forum C++ Programming
    Replies: 4
    Last Post: 07-20-2006, 10:57 AM
  3. newb to C, cant figure something out.
    By Phate4219 in forum C Programming
    Replies: 16
    Last Post: 03-06-2006, 01:47 AM
  4. I cant figure out what is wrong with this
    By C++angel in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2006, 10:57 PM
  5. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM