DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Cant assign value to string in class?

  1. #1
    Join Date
    Sep 2011
    Posts
    0

    Cant assign value to string in class?

    Hi Im basically new here and new to C++ and I just encountered what seems to be a simple problem that left me scratching my head

    #include <string>

    using namespace std;

    class menu{

    public:
    menu::menu(std::string tempText, int temp_x, int temp_y, int temp_x2, int temp_y2){
    int x = temp_x;
    int y = temp_y;
    int x2 = temp_x2;
    int y2 = temp_y2;
    }

    void menu::showAt(){

    }

    void menu::hide(){

    }

    private:
    string text();
    int x;
    int y;
    int x2;
    int y2;
    };
    that is a class I made which compiles pretty fine, however if I assign a value to text, say

    string text("jdkfdjkf");

    it gives me an error expected ; before token... I have tried everything to my knowledge and I believe you guys are my last chance please help me out :(

  2. #2
    Join Date
    Dec 2007
    Posts
    401
    Make text a member variable of the class.

    We can assign values to variables, not to functions.

    Code:
    class menu
    {
        public:
            menu( std::string tempText, int temp_x, int temp_y, int temp_x2, int temp_y2 )
            {
                text = tempText ;
                // ...
            }
    
        private:
            string text ;
            int x;
            // ...
    };

Similar Threads

  1. Initialise Date type Variable in VB6
    By Lennie in forum VB Classic
    Replies: 9
    Last Post: 11-09-2008, 09:19 PM
  2. Input string was not in a correct format
    By mdengler in forum ASP.NET
    Replies: 0
    Last Post: 11-26-2002, 03:32 PM
  3. Re: App Object (fixes)
    By Rob Teixeira in forum .NET
    Replies: 129
    Last Post: 06-06-2002, 05:23 AM
  4. App Object
    By Rob Teixeira in forum .NET
    Replies: 15
    Last Post: 05-31-2002, 03:30 PM
  5. Database problems
    By Robert Rieth in forum VB Classic
    Replies: 1
    Last Post: 04-11-2000, 03:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center