kise
kise

Reputation: 51

Compiler isn't recognizing overloaded constructor C++

I'm trying to create a symbol table for a basic compiler. I have 2 constructors in my Symbol class-one that takes 4 parameters, and one that takes 5. I have a simple main function in that tries to create a Symbol object, taking in 4 parameters, and then another one with 5 parameters. The compiler complains about the Symbol b with 5 parameters:

error: no matching function for call to ‘Symbol::Symbol(std::string&, std::string&, int, kind, int)’
symbol.h:14: note: candidates are: Symbol::Symbol(const Symbol::string&, const Symbol::string&, int, kind)
 symbol.h:6: note:                 Symbol::Symbol(const Symbol&)

I'm not sure why its saying that there is no matching function to call because it is there. Although I'm not sure if the "const Symbol::string&" being different from "std::string&" is causing some issue, or how to fix that if so.

Here is the main:

int main(){
    string x="x";
    string y="y";
    Symbol a(x,"int",0,SCALAR);
    Symbol b(y,"char",0,ARRAY,5);

    //operator << is overloaded
    cout << a << endl;
    cout << b << endl;
    return 0;
}

symbol.h:

#ifndef SYMBOL_H
#define SYMBOL_H
#include "type.h"
#include <string>

class Symbol{
    typedef std::string string;
    string _name;
    Type _type;

public:
    const string& getName() const;
    const Type& getType() const;
    Symbol(const string& name, const string& specifier, int indirection, kind kind); 
    Symbol(const string& name, const string& specifier, int indirection, kind kind, int length); 
};

std::ostream& operator<<(std::ostream& ostr, const Symbol& symbol);

#endif /*SYMBOL_H*/

symbol.cpp

#include "symbol.h"
#include <iostream>
using namespace std;

/*other member function definitions*/

Symbol::Symbol(const string& name, const string& specifier, int indirection, kind kind)
{
    _name = name;
    Type a(specifier,indirection,kind);
    _type = a;
}

Symbol::Symbol(const string& name, const string& specifier, int indirection, kind kind, int length)
{
    _name = name;

    /*Type is another class that holds the description of the type of the     
     *particular variable, function,etc. declaration
     */

    Type a(specifier,indirection,kind,length);
    _type = a;
}

Upvotes: 2

Views: 832

Answers (1)

kise
kise

Reputation: 51

There was a precompiled header (.gch) file that must have been outdated. Deleted it and recompiled fine.

Upvotes: 3

Related Questions