By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,412 Members | 1,007 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,412 IT Pros & Developers. It's quick & easy.

Implementation problem

P: n/a
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_[i] = std::atoi(nums[i].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
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Kevin Grigorenko wrote in news:bp***********@f04n12.cac.psu.edu:
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/
Jul 19 '05 #2

P: n/a
"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> wrote in message
news:Xn**********************************@195.129. 110.205...
Kevin Grigorenko wrote in news:bp***********@f04n12.cac.psu.edu:
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/

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.