Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,129 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,001 people online right now. Registration is fast and FREE... Join Now!




help with error C2228

 
Reply to this topicStart new topic

help with error C2228, proper syntax

m_reyna_16
post 7 Oct, 2008 - 06:16 PM
Post #1


New D.I.C Head

*
Joined: 7 Oct, 2008
Posts: 4

i am getting an error code C2228 with my code. this are my errors:

CODE
1>------ Build started: Project: Project 2, Configuration: Debug Win32 ------
1>Compiling...
1>clientOp2.cpp
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(6) : error C2228: left of '.getNextItem' must have class/struct/union
1>        type is 'int'
1>        c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(3) : while compiling class template member function 'myarrayListType<elemType> myarrayListType<elemType>::operator /(const myarrayListType<elemType> &) const'
1>        with
1>        [
1>            elemType=int
1>        ]
1>        c:\users\user\documents\visual studio 2005\projects\project 2\project 2\clientop2.cpp(10) : see reference to class template instantiation 'myarrayListType<elemType>' being compiled
1>        with
1>        [
1>            elemType=int
1>        ]
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(7) : error C2228: left of '.getNextItem' must have class/struct/union
1>        type is 'int'
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(18) : error C2228: left of '.add' must have class/struct/union
1>        type is 'int'
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(19) : error C2228: left of '.getNext' must have class/struct/union
1>        type is 'int'
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(20) : error C2228: left of '.getNext' must have class/struct/union
1>        type is 'int'
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(29) : error C2228: left of '.getNext' must have class/struct/union
1>        type is 'int'
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(35) : error C2228: left of '.getNext' must have class/struct/union
1>        type is 'int'
1>Build log was saved at "file://c:\Users\Miguel\Documents\Visual Studio 2005\Projects\Project 2\Project 2\Debug\BuildLog.htm"
1>Project 2 - 7 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



i know that the errors 2-6 i need to declare my union or my class (pretty self explanatory) but i dont know the proper syntax to do it, also, i dont know what the first error is. any help? this is my .cpp file:

CODE
template<class elemType>
myarrayListType<elemType> myarrayListType<elemType>::operator/(const myarrayListType<elemType>& rOperand) const
{
int L1, L2, L3;

L1 = L1.getNextItem();
L2 = L2.getNextItem();

// Exit when we reach the end of one
// of the lists.
while( L1 != NULL && L2 !=NULL )
{
if (L1 == L2)
{
// If the two items are equal, then they
// are in the intersection of the two lists
// so save a copy in the result list.
L3.add(L1);
L1 = L1.getNext();
L2 = L2.getNext();
}
else if (L1 < L2)
{
// If the item in list1 is less than that
// of list2, then get the next item in list1.
// This works because the lists are sorted.
// The assumption is that they are sorted from
// lowest to highest.
L1 = L1.getNext();
}
else
{
// If the item in list2 is less than that
// of list1, then get the next item in list2.
L2 = L2.getNext();
}

// We've reached the end of one list or another.
// All remaining elements of either list are not
// in the intersection of the two lists.
return L3;
}
//Complete to Return the intersection of two lists
    
}



and my .h file:

CODE
#ifndef H_myarrayListType
#define H_myarrayListType

#include <iostream>
#include <cassert>
using namespace std;

template<class elemType>
class myarrayListType
{
    
    template<class elemType>
    friend ostream& operator<<(ostream&, const myarrayListType<elemType>&);

public:
    myarrayListType(int mS);
    myarrayListType(const myarrayListType<elemType> &otherList);
    ~myarrayListType();
    bool    isEmpty();
    bool    isFull();
    int        listSize();
    int        insertAt(int pos, elemType item);
    int        retrieveAt(int pos, elemType &item);
    int        search(elemType item);
    int        remove(elemType item);
    void    print();
    void    clear();
    elemType*& operator[](int);
    const elemType* operator[](int) const;
    myarrayListType operator+(const myarrayListType<elemType>&) const;
    myarrayListType operator/(const myarrayListType<elemType>&) const;


private:
    int    size;
    elemType **list;
    int    maxSize;


};

template<class elemType>
myarrayListType<elemType>::myarrayListType(int mS)
{
    list = new elemType*[mS];
    assert(list != NULL);
    for (int i=0; i<mS; i++)
        list[i] = NULL;
    maxSize = mS;
    size = 0;
}

template<class elemType>
myarrayListType<elemType>::myarrayListType(const myarrayListType<elemType> &otherList)
{
    maxSize = otherList.maxSize;
    size = otherList.size;
    list = new elemType*[maxSize];
    assert(list!=NULL);
    for (int i=0; i<maxSize; i++)
    {
        if ( otherList[i] != NULL )
        {
            list[i] = new elemType;
            assert(list[i]!=NULL);
            *list[i] = *otherList[i];
        }
        else
            list[i] = NULL;
    }
}

template<class elemType>
myarrayListType<elemType>::~myarrayListType()
{
    clear();
    delete []list;
}

template <class elemType>
bool myarrayListType<elemType>::isEmpty()
{
    if ( size == 0 )
        return true;
    return false;
}

template<class elemType>
bool myarrayListType<elemType>::isFull()
{
    return ( size == maxSize );
}

template<class elemType>
int myarrayListType<elemType>::listSize()
{
    return size;
}

template<class elemType>
int myarrayListType<elemType>::insertAt(int pos, elemType item)
{
    if ( size < maxSize ) //room for one more
    {    
        if ( list[pos] == NULL ) //empty spot
        {
            list[pos] = new elemType;
            assert (list[pos] != NULL);
            *list[pos] = item;
            size++;
            return pos;
        }
        else{ // list at pos is not empty, proceed to find an empty spot
            for (int i=0; i<maxSize; i++)
            {
                if ( list[i] == NULL ) //empty spot
                {
                    list[i] = new elemType;
                    assert (list[pos] != NULL);
                    *list[i] = item;
                    size++;
                    return i;
                }
            }
        }

    }
    return -1;
}

template<class elemType>
int myarrayListType<elemType>::retrieveAt(int pos, elemType &item)
{
    if ( list[pos] != NULL )
    {
        item = *list[pos];
        return pos;
    }
    return -1;
}

template<class elemType>
int myarrayListType<elemType>::search(elemType item)
{
    for (int i=0; i<maxSize; i++)
    {
        if ( list[i] != NULL && *list[i] == item ) //empty spot
            return i;
    }
    return -1;
}

template<class elemType>
int myarrayListType<elemType>::remove(elemType item)
{
    int pos=search(item);
    if ( pos != -1 )
    {
        delete list[pos];
        list[pos] = NULL;
        return pos;
        size--;
    }
    return -1;
}

template<class elemType>
void myarrayListType<elemType>::print()
{
    for (int i=0; i<maxSize; i++)
        if ( list[i] != NULL )
            cout << *list[i] << " ";
        cout << endl;
    return;
}
template<class elemType>
void myarrayListType<elemType>::clear()
{
    for (int i=0; i<maxSize; i++)
    {
        if ( list[i] != NULL )
            delete list[i];
        list[i] = NULL;
    }
    size = 0;
}


template<class elemType>
elemType*& myarrayListType<elemType>::operator[](int index)
{
    assert(0<=index && index<maxSize);
    return (list[index]);
}


template<class elemType>
const elemType* myarrayListType<elemType>::operator[](int index) const
{
    assert(0<=index && index<maxSize);
    return (list[index]);
}


template<class elemType>
ostream& operator<<(ostream& out, const myarrayListType<elemType>& listToPrint)
{
    for (int i=0; i<listToPrint.maxSize; i++)
        if ( listToPrint[i] != NULL )
            out << *listToPrint[i] <<endl;
        out << endl;
    return out;
}

#include "unionOp.cpp"
#include "intersectionOp.cpp"

#endif
User is offlineProfile CardPM

Go to the top of the page

FrozenSnake
post 7 Oct, 2008 - 06:17 PM
Post #2


D.I.C Head

**
Joined: 30 Jul, 2008
Posts: 55


My Contributions


http://msdn.microsoft.com/en-us/library/3y365xw6(VS.80).aspx
User is offlineProfile CardPM

Go to the top of the page

m_reyna_16
post 7 Oct, 2008 - 06:24 PM
Post #3


New D.I.C Head

*
Joined: 7 Oct, 2008
Posts: 4

QUOTE(FrozenSnake @ 7 Oct, 2008 - 07:17 PM) *

thanks but i had already looked at that and cant figure it out cuz im not using a struct, i am using a class and a union on my program.
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 7 Oct, 2008 - 06:27 PM
Post #4


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,324



Thanked 57 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


The error :

error C2228: left of '.getNextItem' must have class/struct/union

Your code :

CODE
int L1, L2, L3;

L1 = L1.getNextItem()


Last time I checked int stood for integer.

The link that was provide is an accurate fix for this error.
User is offlineProfile CardPM

Go to the top of the page

m_reyna_16
post 7 Oct, 2008 - 06:53 PM
Post #5


New D.I.C Head

*
Joined: 7 Oct, 2008
Posts: 4

QUOTE(no2pencil @ 7 Oct, 2008 - 07:27 PM) *

The error :

error C2228: left of '.getNextItem' must have class/struct/union

Your code :

CODE
int L1, L2, L3;

L1 = L1.getNextItem()


Last time I checked int stood for integer.

The link that was provide is an accurate fix for this error.


the thing is i dont know how to work with structs. what do you add in a struct?
User is offlineProfile CardPM

Go to the top of the page

m_reyna_16
post 7 Oct, 2008 - 08:30 PM
Post #6


New D.I.C Head

*
Joined: 7 Oct, 2008
Posts: 4

QUOTE(m_reyna_16 @ 7 Oct, 2008 - 07:53 PM) *

QUOTE(no2pencil @ 7 Oct, 2008 - 07:27 PM) *

The error :

error C2228: left of '.getNextItem' must have class/struct/union

Your code :

CODE
int L1, L2, L3;

L1 = L1.getNextItem()


Last time I checked int stood for integer.

The link that was provide is an accurate fix for this error.


the thing is i dont know how to work with structs. what do you add in a struct?


OK SO I FOUND OUT HOW TO USE STRUCTS, AND FIXED IT BUT AM NOW GETTING THIS ERRORS:

CODE
1>c:\users\miguel\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(11) : error C2144: syntax error : 'List' should be preceded by ';'
1>c:\users\miguel\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(11) : error C2143: syntax error : missing ';' before '<end Parse>'


and this is my .cpp file after the fix:
CODE
template<class elemType>
myarrayListType<elemType> myarrayListType<elemType>::operator/(const myarrayListType<elemType>& rOperand) const

struct List
{
    char L1[5];
    char L2[5];
    char L3[10];

    int L1,L2,L3;
};
//int L1, L2, L3;

L1 = L1.getNextItem();
L2 = L2.getNextItem();

// Exit when we reach the end of one
// of the lists.
while( L1 != NULL && L2 !=NULL )
{
if (L1 == L2)
{
// If the two items are equal, then they
// are in the intersection of the two lists
// so save a copy in the result list.
L3.add(L1);
L1 = L1.getNext();
L2 = L2.getNext();
}
else if (L1 < L2)
{
// If the item in list1 is less than that
// of list2, then get the next item in list1.
// This works because the lists are sorted.
// The assumption is that they are sorted from
// lowest to highest.
L1 = L1.getNext();
}
else
{
// If the item in list2 is less than that
// of list1, then get the next item in list2.
L2 = L2.getNext();
}

// We've reached the end of one list or another.
// All remaining elements of either list are not
// in the intersection of the two lists.
return L3;
}
//Complete to Return the intersection of two lists
    
}
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 8 Oct, 2008 - 01:20 AM
Post #7


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,324



Thanked 57 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


I'm not sure why you got the other errors, but you can't have integers & chars with the same variable name. They must be unique....

CODE

    char L1[5];
    char L2[5];
    char L3[10];

    int L1,L2,L3; // These are the same names as your chars...
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 11:50AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month