0

Hello everyone.. I small snippet about me. This is my first post, and I just decided to start coding in C++ a couple weeks ago, so needless to say, I'm a newbie. I bought a Beginning C++ book to help me with initial concepts. On to the reason for my post.

My compiler (g++) returns two errors when I try to compile this code:

#include <iostream>
#include <string>

class Object
{
public:
    Object(std::string name);
    std::string GetName();
private:
    std::string mName;
}

Object::Object(std::string name) {
    mName = name;
}

std::string Object::GetName() {
    return mName;
}

int main() {
    std::string objName = "";
    
    Object obj1("Fred");
    objName = obj1.GetName();
    
    std::cout << objName;

    return 0;
}

And these are the errors:
Line 13 new types may not be defined in a return type
Line 13 return type specification for constructor invalid

I've been staring at this for a couple hours now and have hit a block. Any help would be appreciated, thanks. :D

2
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by jdphenix
0

Wow.

I can't believe it.

Well, good to know what typos I commonly make so I know what to look for! Thanks :D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.