Results 1 to 2 of 2

Thread: Cannot Use .This To Qualify Variable In C++

  1. #1
    Senior Member crazyfool's Avatar
    Join Date
    Jan 2008
    Posts
    761
    Thanks
    77
    Thanked
    38 times in 38 posts
    • crazyfool's system
      • Motherboard:
      • Striker Extreme
      • CPU:
      • Q6600
      • Memory:
      • OCZ 6400 2 x 2GB
      • Storage:
      • Samsung Spinpoint 500GB
      • Graphics card(s):
      • BFG 8800 GT OC 512MB
      • PSU:
      • Coolermaster Real Power Pro 850w
      • Case:
      • Coolermaster CM-690
      • Operating System:
      • XP, Vista, Windows 7 & Ubuntu
      • Monitor(s):
      • Samsung 2232BW

    Cannot Use .This To Qualify Variable In C++

    hey guys,
    Was just trying to start working on my new project and I got this weird error:
    error C2228: left of '.name' must have class/struct/union
    Below is my code, just a simple class:

    #include <string>

    using namespace std;

    class X
    {
    string name;

    X(string name)
    {
    this.name = name;
    }

    }

    Now I know I'm a little rusty but I'm don't think I've done anything wrong. I wouldn't usually ask for help but searching "this" in google doesn't provide helpful results.

  2. #2
    HEXUS webmaster Steve's Avatar
    Join Date
    Nov 2003
    Posts
    14,276
    Thanks
    292
    Thanked
    837 times in 473 posts

    Re: Cannot Use .This To Qualify Variable In C++

    this is a pointer so you need to dereference it. Plus you're missing a semicolon at the end of your class declaration:
    Code:
    #include <string>
    
    using namespace std;
    
    class X
    {
    string name;
    
    X(string name)
    {
    this->name = name;
    }
    
    };
    PHP Code:
    $s = new signature();
    $s->sarcasm()->intellect()->font('Courier New')->display(); 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 10-05-2007, 12:10 AM
  2. Replies: 6
    Last Post: 08-04-2006, 09:47 AM
  3. Trying to retreive UserDomain variable from a remote machine
    By farooqm in forum Help! Quick Relief From Tech Headaches
    Replies: 1
    Last Post: 06-02-2006, 12:51 PM
  4. Variable Bitrate - Constant Bitrate...
    By retroborg in forum Software
    Replies: 1
    Last Post: 12-08-2004, 02:56 PM
  5. Displaying a System variable on a Web Page
    By Jiff Lemon in forum Software
    Replies: 3
    Last Post: 08-10-2003, 03:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •