LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Non type class (https://www.linuxquestions.org/questions/programming-9/non-type-class-787021/)

gregarion 02-04-2010 11:40 AM

Non type class
 
Hey guys basically, im trying to save a value in a member object in c ++.


Code:

class readNasdaq
{
    public:
        void Nasdaq(fstream&) ;
        string value ;
    private :
};

This is in my cpp file

string NasdaqValue = line.substr( LocationNasdaqValue , LengthOfNasdaqValue ) ;

Code:

  cout << "  " << endl ;
cout << "The Value Index of Nasdaq is " << NasdaqValue << endl ;

 value = NasdaqValue ;

Am i right to say that now value can be called to be used at other places by

readNasdaq.w();
w.value();

But for some reason, i keep getting an error message saying...

Code:

financetest.cpp:28: error: request for member ‘Nasdaq’ in ‘w’, which is of non-class type ‘readNasdaq ()()'
why is that? and how do i solve this problem?

irmin 02-04-2010 01:54 PM

Can you post more of your source code (if you want) to allow tracing the error?

Code:

readNasdaq.w();
w.value();

Why is there a dot between the readNasdaq and the w? The class readNasdaq does not contain a member "w".

You cannot call "value" in an object of class "readNasdaq", because class std::string does not implement the operator().

Posting more source code can really help. Especially post line 28, where the error resides.

johnsfine 02-04-2010 03:16 PM

Quote:

Originally Posted by gregarion (Post 3852668)
This is in my cpp file
...
value = NasdaqValue ;

But where in your cpp? I expect you intend value to be that member of an object of type readNasdaq, but that line would only make sense in a member function of readNasdaq, which you don't seem to have. Also you don't seem to have the object either.

Quote:

Am i right to say that now value can be called to be used at other places by

readNasdaq.w();
w.value();
I think I'm guessing right that your intent for
readNasdaq.w();
is to define w as an object of type readNasdaq using the default constructor. The correct syntax for that would be:

readNasdaq w;

Your intent for w.value() is to access the value member of w? The correct syntax for that would be: w.value

But remember value is a member of each object of type readNasdaq, so you can't communicate a value by setting it in one object and accessing it in another.

If you want one value for all readNasdaq, make it a static class member, not an ordinary class member.


All times are GMT -5. The time now is 09:00 AM.