Passing String to Function

I'm trying to pass a string to a function.

1
2
3
MyClass x();

x.add("some name", 11);


1
2
3
4
void MyClass::add(const char *name, int someint)
{
  //do some work
}


but getting an error when trying to do this.

request for member `add' in `x', which is of non-class type `MyClass ()()'
Last edited on
MyClass x(); is a function declaration (keyword: most vexing parse).
Write MyClass x; or MyClass x{}; (C++11).
now i'm getting a new set of errors...
1
2
3
4
undefined reference to 'MyClass::MyClass()'
undefined reference to 'MyClass::add(char *, int)' //I made changes to the function, removed const
undefined reference to 'MyClass::~MyClass()' 
undefined reference to 'MyClass::~MyClass()' 
Sounds like you forgot to define or link these functions.
in my main.cpp

#include "MyClass.h"

in my MyClass.cpp

#include "MyClass.h"


i'm using codeblocks, do i need to do anything special?
Last edited on
You need to add MyClass.cpp to the project (Project/Add files), so it is built and linked.
When you create new files within Code::Blocks (File/New/Empty File), this is done automatically.
ahh cool,

just started using codeblocks so i missed that part :)

thanks for the help guys
Topic archived. No new replies allowed.