user3090837
user3090837

Reputation: 25

Getting error like "Type qualifier 'std' must be a struct or class name in C++

When i compile the code below, i got the error like Type qualifier 'std' must be a struct or class name. Kindly find the code below-

#include <iostream>

int foo(int i)
{
  return 2;
}

double foo(double d)
{
  return 4.0;
}

struct Computer
{
  int foo(int i)
  {
    return 8; 
  }
};

struct Gateway : public Computer
{
  double foo(double d)
  {
    return 16.0; 
  }
};

int main(int argc, char** argv)
{
  Gateway g;

  std::cout << foo(1) + foo(1.0) + g.foo(1) + g.foo(1.0) << std::endl;

  return 0;
}

Kindly check it and suggest how to resolve it.

Upvotes: 1

Views: 5021

Answers (1)

johnsyweb
johnsyweb

Reputation: 141998

Your code compiles and runs fine.

You are getting this error because your compiler is not compliant with the C++ standard.

Turbo C++ is horrendously outdated.

It is time to get a new, free, standard compliant compiler. Clang for example.


In answer to your second question, in the comments, Gateway::foo hides Computer::foo, which is why Gateway::foo is invoked for both int and double arguments. If this is not what you intended, you could alter your struct like so:

struct Gateway : public Computer
{
    using Computer::foo;

    double foo(double d)
    {
        return 16.0;
    }
};

See it run!

Upvotes: 2

Related Questions