Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have a class Stockauto with a constructor Stockauto(int, date*,double,car*,int).
Date and car are 2 other objects I use in Stockauto. When creating a DAO I need to use res->getInt(),.....

I always get the error:
cannot convert int to date*.
Does someone know how I can fix this?
In my database there are 3 tables Stockauto, date and cars; with a foreign key from date and cars in Stockauto.
C++
vector<Stockauto*> StockautosDAO::getAll()
{
    ResultSet *res = NULL;
    Statement *stmt = NULL;
    vector<Stockauto*> stockautos;
    try
    {
        if(con == NULL ||con->isClosed())
            con = DatabaseSingleton::getInstance()->getConnection();

        if (con==NULL)
            return stockautos;

        stmt = con -> createStatement();
        res = stmt -> executeQuery ("SELECT * FROM Stockauto");

        while (res -> next())
        {
            //nummer is de volgorde
            Stockauto* stockauto = new Stockauto(res->getInt(1),res->getInt(2), res->getDouble(3), res->getString(4), res->getInt(5));
            stockautos.push_back(stockauto);
        }
        
        stmt->close();
        delete stmt;
        delete res;
        con ->close();
    }
    catch (SQLException &e)
    {
        cout<<"PROBLEM: "<<e.what()<<endl;
        con ->close();
        if(stmt != NULL)
            delete stmt;

        if(res != NULL)
            delete res;
    }

    return stockautos;
}

Error:
c:\users\dries\desktop\software project\groep 4\dev-branch-driesvandevelde\cardealer\cardealer\stockauto'sdao.cpp(62): error C2664: 'Stockauto::Stockauto(int,Datum *,double,Auto *,int)' : cannot convert parameter 2 from 'int32_t' to 'Datum *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Posted
Updated 7-Apr-14 9:17am
v3
Comments
Richard MacCutchan 7-Apr-14 12:20pm    
Your question is not clear, but the implication is that you have something like:

date* pDate;
pDate = res->getInt(); // where getInt() returns an int not a date*
Raul Iloc 7-Apr-14 13:11pm    
You should improuve your question and show us the complete section of code that generate the error!

1 solution

Check this line:

Stockauto* stockauto = new Stockauto(res->getInt(1),res->getInt(2), res->getDouble(3), res->getString(4), res->getInt(5));


As Richard pointed out, res->getInt(2) returns an int, and the Stockauto constructor expects a Datum*.
So either this is not the correct constructor, or your parameter is wrong.
 
Share this answer
 
Comments
Dries89 8-Apr-14 5:36am    
Is there something else I can use? The constructor is correct. I don't think there is something like getPointer....
Rage 8-Apr-14 5:43am    
If the constructor expects a pointer on a Date, why do you insist of giving it an int ? Can you post the getInt and the constructor code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900