Implementation problem

Discussion in 'C++' started by Kevin Grigorenko, Nov 16, 2003.

  1. Basically, I have two classes declared in a header file:

    class Version
    {
    ...
    };

    class BasicRegex
    {
    ...
    std::vector<std::string> split(std::string parseString);
    ...
    };

    Then, in the implementation file, I want to use an instance of the
    BasicRegex class in the implementation of a member function of Version. It
    seems to compile fine when I declare a local object of type BasicRegex in
    the Version member function, but then when I try to call the member function
    split(), VS.NET compiler gives the following error:

    error C2228: left of '.split' must have class/struct/union type

    void Version::setVersion(std::string parseString)
    {
    if(parseString == "") return;
    BasicRegex regex(std::string(separator_)); // separator_ is private
    member data in Version, just a char
    std::vector<std::string> nums;
    nums = regex.split(parseString); // here's the problematic line
    nums_.resize(nums.size()); // nums_ is also local data for
    Version
    for(int i = 0; i < nums.size(); i++)
    {
    nums_ = std::atoi(nums.c_str());
    }
    }

    I can use the BasicRegex object outside of the implementation file (and the
    split member function works fine, so it has something to do with scope here
    I think).

    What can I do to fix this?

    Thank you,
    Kevin Grigorenko
     
    Kevin Grigorenko, Nov 16, 2003
    #1
    1. Advertising

  2. Kevin Grigorenko wrote in news:bp82rm$1jpa$:

    > BasicRegex regex(std::string(separator_)); // separator_ is
    > private
    >


    The above declares a function:

    BasicRegex regex( std::string seperator );

    Parenthesis are allowed to surround the identifier part of a declaration
    to allow stuff like:

    int (*pointer_to_array)[3];

    Solution 1:

    BasicRegex regex( (std::string( seperator ) ) );

    Solution 2 (needs an accesable copy-ctor, but shouldn't call it):

    BasicRegex regex = BasicRegex( std::string( seperator ) );

    HTH.

    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
     
    Rob Williscroft, Nov 16, 2003
    #2
    1. Advertising

  3. "Rob Williscroft" <> wrote in message
    news:Xns94359A75E7132ukcoREMOVEfreenetrtw@195.129.110.205...
    > Kevin Grigorenko wrote in news:bp82rm$1jpa$:
    >
    > > BasicRegex regex(std::string(separator_)); // separator_ is
    > > private
    > >

    >
    > The above declares a function:
    >
    > BasicRegex regex( std::string seperator );
    >
    > Parenthesis are allowed to surround the identifier part of a declaration
    > to allow stuff like:
    >
    > int (*pointer_to_array)[3];
    >
    > Solution 1:
    >
    > BasicRegex regex( (std::string( seperator ) ) );


    Wow, that was simple, Thank you!

    >
    > Solution 2 (needs an accesable copy-ctor, but shouldn't call it):
    >
    > BasicRegex regex = BasicRegex( std::string( seperator ) );
    >
    > HTH.
    >
    > Rob.
    > --
    > http://www.victim-prime.dsl.pipex.com/
     
    Kevin Grigorenko, Nov 16, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tcl

    Implementation Problem.

    tcl, Mar 8, 2006, in forum: VHDL
    Replies:
    12
    Views:
    1,172
    Rod Pemberton
    Mar 23, 2006
  2. Dan
    Replies:
    1
    Views:
    421
    =?Utf-8?B?QWpveQ==?=
    Sep 28, 2004
  3. Michael Tsang
    Replies:
    32
    Views:
    1,155
    Richard Bos
    Mar 1, 2010
  4. Michael Tsang
    Replies:
    54
    Views:
    1,237
    Phil Carmody
    Mar 30, 2010
  5. sanket
    Replies:
    7
    Views:
    1,094
    Tsung
    Nov 3, 2011
Loading...

Share This Page