[C++] Having some troubles with ctors

From: Andrew Falanga (falandr_at_hp.com)
Date: 07/30/04

  • Next message: Mike Wahler: "Re: [C++] Having some troubles with ctors"
    Date: Fri, 30 Jul 2004 12:15:49 -0600
    
    

    The subject line is a little too simple, but who wants a long subject
    line? Here's what's happeing:

    class a {
       private:
         // got some stuff here
       public:
         a(std::string s) {
            // using s.c_str() to pass to some platform spec.
            // functions to fill other data types not given
            // because they too go to platform spec stuff,
            // specifically TCP/IP related data stuff
         }
    };

    class b {
       private:
         a objA;
         // some other stuff
       public:
         b (char* str) {
           std::string s(str);
           a(s);
         }
    };

    So, when I try to compile this I get:

    In constructor `b::b(char*)':
    error: no match for call to `(a) (std::string&)'

    Is this happening because C++, when passing objects, only passes by
    reference rather than value? Second, how am I going to get around this?
      This isn't the first thing I've tried, but I figured it's time I asked
    for help.

    Basically, I have to instantiate an object of type "a" when contrusting
    an object of type "b". In this case, I need to pass it a character
    string representing the hostname of my intended target for connection.
    How am I going to pass these strings in such a way that C++ won't complain?

    ---------------------------------------------
    Andrew R. Falanga (a non-HP employee)
    Hewlett-Packard Company
    11311 Chinden Blvd.
    Boise, Idaho
    ---------------------------------------------
    Please note: The e-mail address is purposely
    mangled. I do not wish my account at HP to
    become a spam haven.


  • Next message: Mike Wahler: "Re: [C++] Having some troubles with ctors"

    Relevant Pages

    • Re: Rotated Text Help Needed
      ... Scalemode was set to vbInches only in the main character drawing routine. ... Private Type LOGFONT ... Private Sub RotateFont ... Dim log_font As LOGFONT ...
      (microsoft.public.vb.general.discussion)
    • Rotated Text Help Needed
      ... position the "glyph" rather than the character cell at the desired position ... Having carried out a quick check (using much larger font sizes) I can see ... Private Type LOGFONT ...
      (microsoft.public.vb.general.discussion)
    • Rotated Text Help Needed
      ... position the "glyph" rather than the character cell at the desired position ... Having carried out a quick check (using much larger font sizes) I can see ... Private Type LOGFONT ...
      (comp.lang.basic.visual.misc)
    • New: Paradise: A Gay Friendly Resort PBEM (free, open-ended, email, human, modern, rpg, abstract
      ... turn Paradise into the Pacific's premier gay resort. ... Private yacht the Angel and a fleet of sail boats, ... character by using any of the staff as a template. ...
      (rec.games.pbm)
    • Need Help converting int -> char -> string & TextArea display(!)
      ... display its contents character-by-character ... Please can someone show me how to read each character ... private TextArea inputTextArea; ... public void actionPerformed ...
      (comp.lang.java.help)