Skip to content

Instantly share code, notes, and snippets.

@TheOpenDevProject
Created December 20, 2015 09:26
Show Gist options
  • Save TheOpenDevProject/5ef87ec7757f9124e21a to your computer and use it in GitHub Desktop.
Save TheOpenDevProject/5ef87ec7757f9124e21a to your computer and use it in GitHub Desktop.
class MyClass{
//For arguments sake to fit with rust just make everything public
public:
std::string _name;
MyClass(std::string name){
this->_name = name;
}
std::string Name(){
return this->_name;
}
void AnotherMethod(){
//What ever
}
}
main(){
MyClass myObject;
myObject.AnotherMethod();
auto x = myObject.Name();
}
@Manishearth
Copy link

struct MyClass {
  pub name: String,
}

impl MyClass {
  fn new(x: String) -> MyClass {
    MyClass {name: s}
  }
  fn Name(self) -> String {
    self.name // might want to make this take `&self` instead and return `&str`
  }
  fn AnotherMethod(&self) {
   //
  }
}

fn main {
 let myObject = MyClass::new("".to_string());
 myObject.AnotherMethod();
 let x = myObject.Name();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment