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
    Object(std::string name);
    std::string GetName();
    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

Recommended Answers

All 2 Replies

Your class is missing a ; at the end
class foo {


I can't believe it.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.