this example grabbed from geeksforgeeks.
// C++ program to demonstrate function
// declaration outside class
#include <bits/stdc++.h>
using namespace std;
class Geeks
{
public:
string geekname;
int id;
// printname is not defined inside class definition
void printname();
// printid is defined inside class definition
void printid()
{
cout << "Geek id is: " << id;
}
};
// Definition of printname using scope resolution operator ::
void Geeks::printname()
{
cout << "Geekname is: " << geekname;
}
int main() {
Geeks obj1;
obj1.geekname = "xyz";
obj1.id=15;
// call printname()
obj1.printname();
cout << endl;
// call printid()
obj1.printid();
return 0;
}
I mean, function like printname
in this example.
And in rust..., this example grabbed from exercism and I modified little bit.
// This stub file contains items which aren't used yet; feel free to remove this module attribute
// to enable stricter warnings.
#![allow(unused)]
pub struct User {
name: String,
age: u32,
weight: f32,
}
impl User {
pub fn new(name: String, age: u32, weight: f32) -> Self;
pub fn name(&self) -> &str;
...
...
}
pub fn User::name(&self) -> &str {
unimplemented!()
}
...
...
like this or somewhat difference, but declare first definition later.
Sorry for my bad english, and therefore I included many lines of code and I needed to add some more detail because SO
wants that.
There's no way to do this in Rust
?
extern
block. But then linking in the actual definition is really delving into the dark arts... there be dragons!