Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #92289

Re: a problem with an program

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c++
Subject Re: a problem with an program
Date 2023-10-01 16:29 +0100
Organization A noiseless patient Spider
Message-ID <87a5t2cqeh.fsf@bsb.me.uk> (permalink)
References <fbfd5e3e-ccff-470d-b2b4-7090c1649e6an@googlegroups.com> <87v8bsagai.fsf@bsb.me.uk> <ufbu2m$1j79g$1@dont-email.me>

Show all headers | View raw


"Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:

> On 2023-09-29 10:13 PM, Ben Bacarisse wrote:
>> karam hello <karamhello2@gmail.com> writes:
>> 
>>>   i have a problem with this program using C++ OOP inheritance
>>>   specially on class c:
>> Your compiler should be telling your what's wrong.  It might not do so
>> very clearly, but it should be pointing you to where the problem is.
>> But let me play compiler here and give you a different error message...
>> 
>>> #include <iostream>
>>> using namespace std;
>>> class a{
>>>      private:
>>>          string name;
>>>          int age;
>>>      public:
>>>          a(string n, int a){
>>>              name = n;
>>>              age = a;
>>>          }
>>> };
>>> class b{
>>>      private:
>>>          string email;
>>>      public:
>>>          b(string em){
>>>              email = em;
>>>          }
>>> };
>>> class c:public a, public b{
>>>      public:
>>>          c(string n, int a, string em) : a(n, a), b(em){}
>> line 23 position 41 ______________________^
>> a is an int.  I can't call a(n, a) when a is an int.
>> 
>>> };
>>> int main(){
>>>      c c1("k", 10, "com");
>>> }
>> Does that help?
>
> g++ complains about that thing, but Visual C++ compiles the code just fine
> as C++17.

Curious.  Which one is correct?  Without studying the standard, I would
have thought that gcc has it right.

-- 
Ben.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

a problem with an program karam hello <karamhello2@gmail.com> - 2023-09-29 12:59 -0700
  Re: a problem with an program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-09-29 21:13 +0100
    Re: a problem with an program "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-10-01 16:00 +0200
      Re: a problem with an program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-10-01 16:29 +0100
      Re: a problem with an program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-10-04 01:56 +0100
  Re: a problem with an program David Brown <david.brown@hesbynett.no> - 2023-09-30 16:57 +0200

csiph-web